From 66c0b704178b10bb466664caf1955664f22ec699 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Wed, 23 Mar 2022 17:53:42 +0800 Subject: [PATCH] refactor: use tf matrix --- src/voronoi/_impl/_vrn2_space_cells_impl.scad | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/voronoi/_impl/_vrn2_space_cells_impl.scad b/src/voronoi/_impl/_vrn2_space_cells_impl.scad index 5ca44d4f..51966969 100644 --- a/src/voronoi/_impl/_vrn2_space_cells_impl.scad +++ b/src/voronoi/_impl/_vrn2_space_cells_impl.scad @@ -23,10 +23,24 @@ function _cells_lt_before_intersection(shape, size, points, pt, half_region_size let( v = p - pt, offset = (pt + p) / 2 - v / norm(v) * half_region_size, - a = atan2(v.y, v.x) + a = atan2(v.y, v.x), + cosa = cos(a), + sina = sin(a), + m = [ + [1, 0, offset.x], + [0, 1, offset.y], + [0, 0, 1] + ] + * + [ + [cosa, -sina, 0], + [sina, cosa, 0], + [0, 0, 1] + ] ) [ for(sp = shape) - ptf_rotate(sp, a) + offset + let(transformed = m * [each sp, 1]) + [transformed.x, transformed.y] ] ];