I suck at trig...

This topic is 3703 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm just trying to find the current angle on a sphere so i can rotate the camera by some amount and then set the new position and target for the camera. I'm getting mixed up in the inverse trig functions... precifically the range of the functions My code is messed up right here and it's taking me a while to figure out what the what is correct
  float angle = atan( proj_onto_x_z.z_ / proj_onto_x_z.x_ );

// if x is positive we are on the right and all is well
// if x is negative we are on the left side

if( pos.x_ < 0)
{
if(pos.z_ > 0) // we are in quadrant II
{
angle =  1.57 + (1.57 - angle);
}
else // we are in quadrant III
{
angle = 3.14159 + angle;
}
}


Any help is appreciated thanks stringa

Share on other sites
If you want your angle to range from [0, 2pi], just do

std::atan2(y, x) + pi;

atan2 returns an angle between [-pi, +pi], maybe that will help you with your confusion of the range of the atan function?

That way you don't have to worry about divide by zero at all.

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 16
• 12
• 20
• 12
• 19
• Forum Statistics

• Total Topics
632163
• Total Posts
3004514

×