clamping radians within a given range

Hi, my math is pretty awful…

I’m trying to clamp an angle within a specific range with this piece of code (c#):

float a = Mathf.Clamp( Mathf.Atan2( p.y, p.x ), -Mathf.Deg2Rad*coneAngle, Mathf.Deg2Rad*coneAngle );

Unfortunately, when the coordinates px and p.y are both negative (so are in the bottom left quadrant) the returned clamped value is on the wrong side…

What is my schoolboy error? :slight_smile:

atan2 returns a negative value for the lower left and a positive for lower right. so with this code you will get popping when your angle crosses from LR to LL.

Not sure what you are trying to do with it so not sure what result you expect!