Renamed planar coords transforms.

This commit is contained in:
Revar Desmera 2019-05-27 12:25:13 -07:00
parent ac9ef3b9e4
commit df83724d6e
2 changed files with 24 additions and 25 deletions

View file

@ -199,41 +199,40 @@ function xy_to_polar(x,y=undef) = let(
) [norm([xx,yy]), atan2(yy,xx)]; ) [norm([xx,yy]), atan2(yy,xx)];
// Function: xyz_to_planar() // Function: project_plane()
// Usage: // Usage:
// xyz_to_planar(point, a, b, c); // project_plane(point, a, b, c);
// Description: // Description:
// Given three points defining a plane, returns the projected planar // Given three points defining a plane, returns the projected planar [X,Y] coordinates of the
// [X,Y] coordinates of the closest point to a 3D `point`. The origin // closest point to a 3D `point`. The origin of the planar coordinate system [0,0] will be at point
// of the planar coordinate system [0,0] will be at point `a`, and the // `a`, and the Y+ axis direction will be towards point `b`. This coordinate system can be useful
// Y+ axis direction will be towards point `b`. This coordinate system // in taking a set of nearly coplanar points, and converting them to a pure XY set of coordinates
// can be useful in taking a set of nearly coplanar points, and converting // for manipulation, before convering them back to the original 3D plane.
// them to a pure XY set of coordinates for manipulation, before convering function project_plane(point, a, b, c) =
// them back to the original 3D plane.
function xyz_to_planar(point, a, b, c) =
let( let(
u = normalize(b-a), u = normalize(b-a),
v = normalize(c-a), v = normalize(c-a),
n = normalize(cross(u,v)), n = normalize(cross(u,v)),
w = normalize(cross(n,u)), w = normalize(cross(n,u)),
relpoint = point-a relpoint = is_vector(point)? (point-a) : translate_points(point,-a)
) [relpoint * w, relpoint * u]; ) relpoint * transpose([w,u]);
// Function: planar_to_xyz() // Function: list_plane()
// Usage: // Usage:
// planar_to_xyz(point, a, b, c); // list_plane(point, a, b, c);
// Description: // Description:
// Given three points defining a plane, converts a planar [X,Y] // Given three points defining a plane, converts a planar [X,Y] coordinate to the actual
// coordinate to the actual corresponding 3D point on the plane. // corresponding 3D point on the plane. The origin of the planar coordinate system [0,0]
// The origin of the planar coordinate system [0,0] will be at point // will be at point `a`, and the Y+ axis direction will be towards point `b`.
// `a`, and the Y+ axis direction will be towards point `b`. function lift_plane(point, a, b, c) =
function planar_to_xyz(point, a, b, c) = let( let(
u = normalize(b-a), u = normalize(b-a),
v = normalize(c-a), v = normalize(c-a),
n = normalize(cross(u,v)), n = normalize(cross(u,v)),
w = normalize(cross(n,u)) w = normalize(cross(n,u)),
) a + point.x * w + point.y * u; remapped = point*[w,u]
) is_vector(remapped)? (a+remapped) : translate_points(remapped,a);
// Function: cylindrical_to_xyz() // Function: cylindrical_to_xyz()

View file

@ -173,7 +173,7 @@ function hull3d_faces(points) =
plane = plane3pt_indexed(points, a, b, c), plane = plane3pt_indexed(points, a, b, c),
d = _find_first_noncoplanar(plane, points, 3) d = _find_first_noncoplanar(plane, points, 3)
) (d == len(points))? /* all coplanar*/ let ( ) (d == len(points))? /* all coplanar*/ let (
pts2d = [ for (p = points) xyz_to_planar(p, points[a], points[b], points[c]) ], pts2d = [ for (p = points) project_plane(p, points[a], points[b], points[c]) ],
hull2d = hull2d_path(pts2d) hull2d = hull2d_path(pts2d)
) hull2d : let( ) hull2d : let(
remaining = [for (i = [3:1:len(points)-1]) if (i != d) i], remaining = [for (i = [3:1:len(points)-1]) if (i != d) i],