Click here to Skip to main content
12,759,971 members (32,029 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked
Posted 23 May 2011

Angle between two points and x-axis

, 23 May 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Tefik Becirovic
Systems Engineer
Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionCalculate angle between two points Pin
Ravi.Kumar02112-Jan-14 7:55
professionalRavi.Kumar02112-Jan-14 7:55 
GeneralUm ... two points define a line. You need three to define an... Pin
Chris Trelawny-Ross23-May-11 10:14
memberChris Trelawny-Ross23-May-11 10:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 23 May 2011
Article Copyright 2011 by Tefik Becirovic
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid