Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8696183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:13:12+00:00 2026-06-13T01:13:12+00:00

Possible Duplicate: How to calculate the angle between two points relative to the horizontal

  • 0

Possible Duplicate:
How to calculate the angle between two points relative to the horizontal axis?

I’ve been looking for this for ages and it’s just really annoying me so I’ve decided to just ask…

Provided I have two points (namely x1, y1, and x2, y2), I would like to calculate the angle between these two points, presuming that when y1 == y2 and x1 > x2 the angle is 180 degrees…

I have the below code that I have been working with (using knowledge from high school) and I just can’t seem to produce the desired result.

float xDiff = x1 - x2;
float yDiff = y1 - y2;
return (float)Math.Atan2(yDiff, xDiff) * (float)(180 / Math.PI);

Thanks in advance, I’m getting so frustrated…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:13:13+00:00Added an answer on June 13, 2026 at 1:13 am

    From what I’ve gathered, you want the following to hold:

    • Horizontal line: P1 -------- P2 => 0°
    • Horizontal line: P2 -------- P1 => 180°

    Rotating the horizontal line clockwise

    You said, you want the angle to increase in clockwise direction.

    Rotating this line P1 -------- P2 such that P1 is above P2, the angle must thus be 90°.

    If, however, we rotated in the opposite direction, P1 would be below P2 and the angle is -90° or 270°.

    Working with atan2

    Basis: Considering P1 to be the origin and measuring the angle of P2 relative to the origin, then P1 -------- P2 will correctly yield 0.

    float xDiff = x2 - x1;
    float yDiff = y2 - y1;
    return Math.Atan2(yDiff, xDiff) * 180.0 / Math.PI;
    

    However, atan2 let’s the angle increase in CCW direction.
    Rotating in CCW direction around the origin, y goes through the following values:

    • y = 0
    • y > 0
    • y = 0
    • y < 0
    • y = 0

    This means, that we can simply invert the sign of y to flip the direction. But because C#’s coordinates increase from top to bottom, the sign is already reversed when computing yDiff.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do I calculate distance between two latitude longitude points? How do
Possible Duplicate: How to calculate the difference between two dates using PHP? I have
Possible Duplicate: How to calculate the difference between two dates using PHP? When a
Possible Duplicate: How to calculate the difference between two dates using PHP? how can
Possible Duplicate: How to calculate the difference between two dates using PHP? I have
Possible Duplicate: How to calculate the difference between two dates using PHP? How to
Possible Duplicate: How to calculate the difference between two dates using PHP? I have
Possible Duplicate: how to calculate difference between two dates using java I'm trying something
Possible Duplicate: Calculate number of days between two given dates Is there a way
Possible Duplicate: How to calculate relative path between 2 directory path? I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.