Original Post
🔒 Locked
Which angle?
Advertisement
Use this method to get the angle in degrees between two points. Result will be between 0 and 360, or -1 if the points are the same.
distance.X = target.X - you.X
distance.Y = target.Y - you.Y
/* Returns the angle between two points given
* the X and Y distance between those two points.
* Returns -1 if the two points are at the same
* coordinates.
*/
public static double atanfull(double x, double y)
{
if (x == 0 && y == 0)
return -1;
double angle;
angle = 90 - Math.toDegrees(Math.atan(y/x));
if (x == 0)
if (y < 0)
angle = 180;
else
angle = 0;
if (x < 0)
angle += 180;
return angle;
}
[edited by - Phaelax on March 2, 2004 9:59:59 PM]
distance.X = target.X - you.X
distance.Y = target.Y - you.Y
/* Returns the angle between two points given
* the X and Y distance between those two points.
* Returns -1 if the two points are at the same
* coordinates.
*/
public static double atanfull(double x, double y)
{
if (x == 0 && y == 0)
return -1;
double angle;
angle = 90 - Math.toDegrees(Math.atan(y/x));
if (x == 0)
if (y < 0)
angle = 180;
else
angle = 0;
if (x < 0)
angle += 180;
return angle;
}
[edited by - Phaelax on March 2, 2004 9:59:59 PM]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement