#### Archived

This topic is now archived and is closed to further replies.

# Calculating angles...

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

## Recommended Posts

I''m working on implementing gravity in my game. I have a planet as the center, and I want to figure out the angle from the planet to the ship. But the problem is, I can''t figure out how to calculate the angle. 0,0 the planet''s location X,Y the ship''s location X,Y can be either positive or negative. How will I calculate this? Is this correct? float Angle = cos(Y); or Angle = sin(X); Man I''m very rustic with my math

##### Share on other sites
  * planet (px, py)  |\--------------------- angle a  | \ H L|  \    |___* ship (sx, sy)    C

H*H = sqrt(L*L + C*C)

C=Sin(a)/H <=> Sin(a) = C*H <=> a=Sin-1(C*H)

i think that's it but i'm not sure, my math aint that sharp

forgot to say that
C=px-sx
L=py-sy

but again am not sure

[edited by - luxitan on February 9, 2003 8:11:03 PM]

[edited by - luxitan on February 9, 2003 8:11:20 PM]

##### Share on other sites
Thanks. Is there a math function for arc tan? Like < cmath >'s sin() and cos()?

If not, I can just do cos()/sin(); instead

Edit: Blasted < >!

[edited by - Zeraan on February 9, 2003 10:28:40 PM]

##### Share on other sites
Does atan() suit your fancy? If not, check out atan2()

yup thats it

Thanks

##### Share on other sites
There isn''t actually an angle to find in your problem unless you introduce a third point into the equation.

##### Share on other sites
...there is an angle to find, but it will be with reference to a particular axis eg: 25 degrees about Y, from the positive Z axis(looking down the Y axis). So essentially treating the problem in 2D. The same can be done for all other axis if need be.

• 10
• 17
• 9
• 13
• 41