Jump to content
• Advertisement

#### Archived

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

# Finding angle between two points

This topic is 6932 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 have two points on a 2d plane, and I''m trying to find the angle between them. The method I have so far, is to pretend that they make up the hypotenuse of a right triangle and then do an arctangent with the height divided by the width. I tried speeding this up with a lookup table, but the arctangent increases exponentially. The way I have works.. but I don''t like it. Is there a better way that any of you can think of? The function should take two x, y coordinates and return an angle. (In my game, an angle is a number from 0-255, where 0 is up, 128 is down, 64 is right, etc) Thanks in advance, Adam M. adamm@san.rr.com

#### Share this post

##### Share on other sites
Advertisement
Well I figure that I''ll just use what I have now.. it''s fast enough for what I use it for, and the post I really need help on is this one.

Although if anybody wants to find a better way than what I''m doing (I dont know if one even exists) feel free!

Currently I have a lookup table and it does a binary search over it to find the angle within 6 iterations and like 2% accuracy, which is plenty accurate for me.. if I wanted it more I''d just increase the size of the table

adamm@san.rr.com

#### Share this post

##### Share on other sites
if you think a lookup table for atan is no good, try the lookup table for arc cosine, it''s much more straight formard

angle = acos(width/sqrt(width*width+height*height));

but i''m afraid that one uses an square root which might slow it down. i still think u better use arc tangant

- pouya

#### Share this post

##### Share on other sites
Yeah.. I''m just doing realtime atan().. because this code isn''t time critical

adamm@san.rr.com

#### Share this post

##### Share on other sites
Actually - to be mathematically correct - there IS no angle between two points. Only if you see both points as vectors from the origin.

#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Now

• 15
• 13
• 35
• 39
• Advertisement
×

## Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!