12,243,333 members (42,709 online)
Tip/Trick
alternative version

31.4K views
5 bookmarked
Posted

Angle between two points and x-axis

, 23 May 2011 CPOL
 Rate this:
Calculate angle between two points and the x-axis using C#
Using Math.Atan2 method:

```const double Rad2Deg = 180.0 / Math.PI;
const double Deg2Rad = Math.PI / 180.0;

/// <summary>
/// Calculates angle in radians between two points and x-axis.
/// </summary>
private double Angle(Point start, Point end)
{
return Math.Atan2(start.Y - end.Y, end.X - start.X) * Rad2Deg;
}```

Pay attention: changing the sign of Y-coordinates causes a transformation of the fourth to the first quadrant because .NET coordinate system is not the same as mathematical ones.

Share

 Systems Engineer Germany
No Biography provided

You may also be interested in...

 First Prev Next
 Calculate angle between two points Ravi.Kumar02112-Jan-14 7:55 Ravi.Kumar021 12-Jan-14 7:55
 Um ... two points define a line. You need three to define an... Chris Trelawny-Ross23-May-11 10:14 Chris Trelawny-Ross 23-May-11 10:14
 Last Visit: 31-Dec-99 19:00     Last Update: 30-Apr-16 16:11 Refresh 1