ID:156485
Sep 25 2010, 1:44 pm
|
|
How would I make an Atan2() proc for DM
|
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: /* |
In response to Cody123100
|
|
Ily Cody.
|
ZOMG rage in the cage, I just found out jt_vectors already does this.
I'm a highschool freshman, smd. |
In response to DarkCampainger
|
|
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? |
In response to Garthor
|
|
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.
|
In response to Garthor
|
|
Not a mathematician, but yeah, we basically have the atan2 function because atan can't tell between opposite directions. Atan2 properly accounts for signs (it's a four-quadrant arctan).
|
Oh, and Arctan: