Shortest distance between two angles

float getShortAngle(float a1, float a2)
{
    float angle = abs(a1 - a2)%360;
 
    if(angle > 180)
    angle = 360 - angle;
 
    return angle;
};
 
printf ("%f", getShortAngle(360, 720));

WordPress Pastebin plugin

Tags: , ,

About James

If this were the 80s I'd be sat in front of a C64 or Speccy, or taking VCRs apart.