MATLAB: Direction between points from [0,360]


I have 5 points which has (x,y) position and want to calculate the direction from one point to the other. I used atan2d but the output is confusing. Is there any way to bypass the different signs for counterclockwise and clockwise and get the output to be between [0,360] from clockwise only?

Best Answer

  • The function atan2d gives angles that are from -180 to 180. Not a problem. This works:
    But you want the angles in a CLOCKWISE orientation? You do understand that is not the standard?
    mod(360 - atan2d(y,x),360)
    I won't ask why you need them in a clockwise orientation. The angles that come from this second expression are angles relative to a horizontal line, and proceeding CLOCKWISE around the origin.
    Note that mod still works even if the angles are not integers. For example:
    mod(360 - atan2d(-2,1),360)
    ans =
    So this points at an angle 63 degrees BELOW the right branch of the x-axis.