double direction(double x1, double y1, double x2, double y2)
{
/*
Direction between (x1, y1) and (x2, y2)
(0 to 360, from x axis, counterclockwise, in degrees)
*/
double angle = 0.0;
if(x1 != x2 || y1 != y2)
{
if(y1 == y2)
{
if(x2 < x1) angle = 180.0;
else angle = 0.0;
}
else if(x1 == x2)
{
if(y2 > y1) angle = 270.0;
else angle = 90.0;
}
else
{
angle = atan2(y1 - y2, x2 - x1)*180.0/Script::PI;
if(angle < 0.0)
{
angle = 360.0 + angle;
}
}
}
return angle;
}
Users browsing this forum: No registered users and 1 guest