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

View file

@ -173,7 +173,7 @@ function hull3d_faces(points) =
plane = plane3pt_indexed(points, a, b, c),
d = _find_first_noncoplanar(plane, points, 3)
) (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 : let(
remaining = [for (i = [3:1:len(points)-1]) if (i != d) i],