chiark / gitweb /
funcs: Add rotate2d
[reprap-play.git] / funcs.scad.cpp
index 5857c933a837f888bf22faedda5b455e6df0e973..c34d15707f8fa76e4db729c54fa9d850aa29edc8 100644 (file)
@@ -24,6 +24,9 @@ function determinant2(m) = (m[0][0] * m[1][1] - m[0][1] * m[1][0]);
 
 function clockwise2d(v) = [v[1], -v[0]];
 
+function rotate2d(theta, v) = [ v[0] * cos(theta) - v[1] * sin(theta),
+                               v[1] * cos(theta) + v[0] * sin(theta) ];
+
 // intersection of lines p1..p2 and p3..p4
 function line_intersection_2d(p1,p2,p3,p4) = [
   // from https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line