Direction.Undefined, , , (. ). , , X Y, int, , (, float, decimal double).
static Direction GetDirection(Point p1, Point p2)
{
double rad = Math.Atan2(p2.Y - p1.Y, p2.X - p1.X);
if (rad < 0)
rad = rad + (2 * Math.PI);
var deg = rad * (180 / Math.PI);
if (deg == 0)
return Direction.East;
else if (deg == 45)
return Direction.Northeast;
else if (deg == 90)
return Direction.North;
else if (deg == 135)
return Direction.Northwest;
else if (deg == 180)
return Direction.West;
else if (deg == 225)
return Direction.Southwest;
else if (deg == 270)
return Direction.South;
else if (deg == 315)
return Direction.Southeast;
else
return Direction.Undefined;
}
...
Direction dir;
dir = GetDirection(new Point(0, 0), new Point(1, 0));
Console.WriteLine(dir);
dir = GetDirection(new Point(0, 0), new Point(1, 1));
Console.WriteLine(dir);
dir = GetDirection(new Point(0, 0), new Point(0, 1));
Console.WriteLine(dir);
dir = GetDirection(new Point(0, 0), new Point(-1, 1));
Console.WriteLine(dir);
dir = GetDirection(new Point(0, 0), new Point(-1, 0));
Console.WriteLine(dir);
dir = GetDirection(new Point(0, 0), new Point(-1, -1));
Console.WriteLine(dir);
dir = GetDirection(new Point(0, 0), new Point(0, -1));
Console.WriteLine(dir);
dir = GetDirection(new Point(0, 0), new Point(1, -1));
Console.WriteLine(dir);
...
East
Northeast
North
Northwest
West
Southwest
South
Southeast
, Point X Y , - Direction.Undefined, , , , ..
// "Almost" pointing east...
dir = GetDirection(new Point(0, 0), new Point(1, 0.001));
...
Undefined