3

I am looking for a way to calculate the bearing or azimuth (0-360°) of one drawing point, or pixel, or screen coord, to another.

I currently have the distance portion of it, and with maths not being the favourite subject in my schooling days, I am turning to this for assistance.

I've seen numerous examples of calculating distance and bearing of latitude and longitude, but I only want to calculate screen coordinates. At a later date, I will convert these to Lat/Long.

Screen coordinates originate top/left at (0,0) so I am aware of this. I also need the ability to move the 'origin' with the mouse. This is something that I can already easily do. Part of the question is do I have to convert the points into proper cartesian points (i.e. with negative values of points 'south' and 'west' or 'below' and 'left' of the origin?

Joseph Quinsey
  • 9,553
  • 10
  • 54
  • 77
MadScientist
  • 53
  • 1
  • 5
  • possible duplicate of [How to calculate the angle between two points relative to the horizontal axis?](http://stackoverflow.com/questions/7586063/how-to-calculate-the-angle-between-two-points-relative-to-the-horizontal-axis) – Peter O. Nov 15 '12 at 04:17
  • 1
    Thanks Peter O, This is the most useful find yet. As this gives the angle relative to the horizontal axis, is there a way to modify the code so that 0 or 360 is 'north' of the origin? I am guessing the other way to do it is to add or subtract 90° – MadScientist Nov 15 '12 at 04:36
  • Possible duplicate of [How to calculate the angle between a line and the horizontal axis?](https://stackoverflow.com/questions/7586063/how-to-calculate-the-angle-between-a-line-and-the-horizontal-axis) – Jim G. Jul 09 '17 at 20:30

1 Answers1

1

it is something like arctan( (x2-x1)/(y2-y1) )

Z .
  • 12,657
  • 1
  • 31
  • 56