Difference between 2 angles

Previous topic - Next topic

Kitty Hello

Assume you have 2 angles (and degrees) and you want the difference angle from phi1 to phi2, but also keep the sign for the direction (clockwise or anticlockwise). This function should return the difference angle in a range -180.0 to +180.0 degrees.

Code (glbasic) Select

// distance between 2 angles
FUNCTION DistAngle: phi1, phi2
LOCAL dif = FMOD(phi2-phi1, 360.0)
IF dif<-180 THEN dif = 360.0 + dif
IF dif>180.0 THEN dif = 180.0 - dif