Author Topic: Difference between 2 angles  (Read 2421 times)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10709
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Difference between 2 angles
« on: 2012-Jan-03 »
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
        RETURN dif
ENDFUNCTION

 
« Last Edit: 2012-Jan-03 by Kitty Hello »