12,759,971 members (32,029 online)
Tip/Trick
alternative version

#### Stats

35.3K views
5 bookmarked
Posted 23 May 2011

# 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.

## About the Author

 Systems Engineer Germany
No Biography provided

## Comments and Discussions

 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: 25-Feb-17 15:20 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.