Calculating angles...

Started by
5 comments, last by GameDev.net 21 years, 2 months ago
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
Advertisement
  * 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

[edit]

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]
To be considered a genius you just have to say what everybody knows in a way very few understand
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]
Does atan() suit your fancy? If not, check out atan2()
yup thats it

Thanks
There isn''t actually an angle to find in your problem unless you introduce a third point into the equation.
...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.

This topic is closed to new replies.

Advertisement