ID:156485
Sep 25 2010, 3:44 pm
|
|
How would I make an Atan2() proc for DM
| |
#2 Sep 25 2010, 3:59 pm
|
||
I assume you're trying to find an angle between two points? I'm sure there are more efficient ways of doing this but I used some stuff I learned from Calculus to develop a Get_Angle() proc which uses inverse cosine and some vector math to determine the angle between point (x0,y0) and point (x1,y1).
Anyways here it is:
| ||
#4 Sep 25 2010, 4:41 pm
|
|
ZOMG rage in the cage, I just found out jt_vectors already does this.
I'm a highschool freshman, smd. | |
atan2() (or arctan2() or arctangent2() or whatever you want to call it) is different from just the arctangent function. atan() takes just one argument, which is the ratio y/x. However, the issue here is that the domain and range is then limited to half of the unit circle: y/x = -y/-x, and -y/x = y/-x. The range of the function, therefore, is only -pi/2 to pi/2. The atan2() function solves this by taking two arguments - y and x - and then using that to give a full range.
Granted, it's only a small difference in terms of lines of code (as shown by Lummox's example) but it really makes things neater and less prone to error. Also that's a really poor explanation in retrospect. Anybody who's actually a mathematician able to say things properly? | |
Yep, that's why I linked to Lummox's snippet. I just threw the arctan() function in because his code relies on it, and most people don't know it by heart.
| |
Oh, and Arctan: