Posted By

jatkins on 05/02/13


Tagged

range angle angles


Versions (?)

Keep angle in range (0-360)


 / Published in: JavaScript
 

Released into the public domain.

  1. function keepAngleInRange(angleToUse) { // 0 <= x < 360
  2. var isNegative = angleToUse < 0;
  3.  
  4. angleToUse = Math.abs(angleToUse);
  5. var divisor = div(angleToUse, 360);
  6. angleToUse -= divisor * 360; // remove 360 until it is in range
  7.  
  8. if(isNegative)
  9. angleToUse = 360 - 1 * angleToUse;
  10.  
  11. return angleToUse;
  12. }

Report this snippet  

You need to login to post a comment.