function unitvector2d(v) = v / vectorlen2d(v);
function unitvector(v) = v / vectorlen(v);
+function atan2vector(v) = atan2(v[1], v[0]);
+
// | m[0][0] m[0][1] |
// | m[1][0] m[1][1] |
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