Added modang() to standardize angles to <-180,180>

This commit is contained in:
Revar Desmera 2019-09-23 16:38:07 -07:00
parent 95952ee971
commit a85ea4ecc9

View file

@ -101,6 +101,7 @@ function min_index(vals, all=false) =
function max_index(vals, all=false) =
all ? search(max(vals),vals,0) : search(max(vals), vals)[0];
// Function: posmod()
// Usage:
// posmod(x,m)
@ -113,6 +114,15 @@ function max_index(vals, all=false) =
function posmod(x,m) = (x%m+m)%m;
// Function: modang(x)
// Usage:
// ang = modang(x)
// Description:
// Takes an angle in degrees and normalizes it to an equivalent angle value between -180 and 180.
function modang(x) =
let(xx = posmod(x,360)) xx<180? xx : xx-360;
// Function: modrange()
// Usage:
// modrange(x, y, m, [step])