diff --git a/math.scad b/math.scad index 1af4272..50151a2 100644 --- a/math.scad +++ b/math.scad @@ -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])