Clockwise angle between two lines

I want to calculate the clockwise angle between two segments of line A and B. Thus, the resulting angle should be between 0 and 360-1 degrees. I saw all the other answers in SO, but they gave me negative angles. Thank.

+3
source share
3 answers

To rotate any angle to the range 0-359 in C # you can use the following "algorithm":

public int Normalise (int degrees) {
    int retval = degrees % 360;
    if (retval < 0)
        retval += 360;
    return retval;
}

C # follows the same rules as C and C ++, and i % 360provides you with a value between -359and 359for any integer, then the second line should provide it in the range from 0 to 359 inclusive.

:

    degrees = ((degrees % 360) + 360) % 360;

. , , , .

degrees % 360 -359 359. 360 1 729. % 360 0 359.

+2

:

if degrees is between [-360, 360]
    degrees = (degrees + 360) % 360;
else degrees = (degrees % 360) + 360) % 360;
+2

, 0-360 :

float positive = ( < 0)? (360 + ):

+1

Source: https://habr.com/ru/post/1753100/


All Articles