Jump to content
  • Advertisement

Archived

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

Zeraan

Calculating angles...

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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]

Share this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
...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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!