#### Archived

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

# finding angle between two points

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

## Recommended Posts

i want to write a function that will return the angle between two points i give it (x1, y1, x2, y2). i know that inverse tangent will do this for me, but then you get into problems when you divide by zero and such. is there any quick and easy way to do this? if not, then whats the inverse tangent function in djgpp *sigh* although i didnt wanna do it that way. - jeremiah http://fakemind.com

##### Share on other sites
You could always use the acos() function for each angle.
(supply x/(sqrt(X^2 + y^2))) That will give the angle that connects to each point then subtrac the smaller angle from the bigger one. Hope you don''t have to do this hella times every frame!!!

Jason Mickela
ICQ : 873518
E-Mail: jmickela@sbcglobal.net
------------------------------
"Evil attacks from all sides
but the greatest evil attacks
from within." Me
------------------------------

##### Share on other sites
Inverse sin sin()-1 would also work to.

Tangent is undefined at 90 degrees or pi/2 rad and 270 degrees or 3pi/2 rad. So tangent won't help you in those situations.

Cos and Sin aren't undefined anywhere on the unit circle (Otherwise the circle would have holes I suppose) but there reciprocals Sec and Csc are. Also the reciprocal of Tan Cot is undefined in a few places as well.

Good Luck!

EDIT: griffenjam is right that if you call this a lot of times when you render your scene, it wil be SLLLLLOOOOOOOWWWWWWWW. You could precalculate the angles and store them in some lookup table.

Remember that all those trig functions are really just an infinite series (that is estimated to something like 15 summations by the computer) and they take up a lot of cpu power each time you call them.

Edited by - Viscous-Flow on November 4, 2001 8:23:50 PM

• 36
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631359
• Total Posts
2999539
×