Getting angle between two points
Ok, I'm trying to have an icon face the mouse. I have the mouse location and the icon's location. I want the angle which will make the icon face the mouse location. Simple: atan(dy/dx), right? The problem is that it doesn't work unless the mouse is up and right from the icon. How do I compensate for this? Thanks.
Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
You want to use atan2, not atan:
DESCRIPTION
The atan() and atanf() functions compute the principal value of the arc tangent of x in the range [-pi/2, +pi/2].
versus:
DESCRIPTION
The atan2() and atan2f() functions compute the principal value of the arc tangent of y/x, using the signs of both arguments to determine the quadrant of the return value.
RETURN VALUES
The atan2 function, if successful, returns the arc tangent of y/x in the range [-pi, +pi] radians. If both x and y are zero, the global variable errno is set to EDOM. On the VAX:
atan2(y, x) := atan(y/x) if x > 0,
sign(y)*(pi - atan(|y/x|)) if x < 0,
0 if x = y = 0, or
sign(y)*pi/2 if x = 0 y.
DESCRIPTION
The atan() and atanf() functions compute the principal value of the arc tangent of x in the range [-pi/2, +pi/2].
versus:
DESCRIPTION
The atan2() and atan2f() functions compute the principal value of the arc tangent of y/x, using the signs of both arguments to determine the quadrant of the return value.
RETURN VALUES
The atan2 function, if successful, returns the arc tangent of y/x in the range [-pi, +pi] radians. If both x and y are zero, the global variable errno is set to EDOM. On the VAX:
atan2(y, x) := atan(y/x) if x > 0,
sign(y)*(pi - atan(|y/x|)) if x < 0,
0 if x = y = 0, or
sign(y)*pi/2 if x = 0 y.
Oh, so that's what that's for
Thanks a bunch.
Thanks a bunch.
Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Formula for converting angle to vector? | komirad | 2 | 8,215 |
Jul 29, 2011 07:29 AM Last Post: ThemsAllTook |
|
| Question Regarding the Reflect Angle of a Transition | iBaby | 3 | 3,071 |
Apr 27, 2010 03:15 PM Last Post: JustinFic |
|
| ending location from angle and speed | Kazooless | 5 | 3,962 |
Apr 3, 2009 02:40 PM Last Post: Gillissie |
|
| Angle between two points? | Graphic Ace | 6 | 4,719 |
Nov 8, 2008 12:11 PM Last Post: macnib |
|
| calculating X and Y coordinates w/ an angle and distance | ferum | 13 | 12,866 |
Jun 25, 2008 10:53 PM Last Post: rosenth |
|

