usage fixes

This commit is contained in:
Adrian Mariano 2022-04-03 10:46:05 -04:00
parent f8064d529f
commit c4376bba41

View file

@ -140,7 +140,7 @@ function _point_left_of_line2d(point, line, eps=EPSILON) =
// Function: is_collinear() // Function: is_collinear()
// Usage: // Usage:
// test = is_collinear(a, [b, c], [eps]); // bool = is_collinear(a, [b, c], [eps]);
// Topics: Geometry, Points, Collinearity // Topics: Geometry, Points, Collinearity
// Description: // Description:
// Returns true if the points `a`, `b` and `c` are co-linear or if the list of points `a` is collinear. // Returns true if the points `a`, `b` and `c` are co-linear or if the list of points `a` is collinear.
@ -161,7 +161,7 @@ function is_collinear(a, b, c, eps=EPSILON) =
// Function: point_line_distance() // Function: point_line_distance()
// Usage: // Usage:
// pt = point_line_distance(line, pt, bounded); // dist = point_line_distance(line, pt, [bounded]);
// Topics: Geometry, Points, Lines, Distance // Topics: Geometry, Points, Lines, Distance
// Description: // Description:
// Finds the shortest distance from the point `pt` to the specified line, segment or ray. // Finds the shortest distance from the point `pt` to the specified line, segment or ray.
@ -421,7 +421,7 @@ function line_from_points(points, fast=false, eps=EPSILON) =
// Function: is_coplanar() // Function: is_coplanar()
// Usage: // Usage:
// test = is_coplanar(points,[eps]); // bool = is_coplanar(points,[eps]);
// Topics: Geometry, Coplanarity // Topics: Geometry, Coplanarity
// Description: // Description:
// Returns true if the given 3D points are non-collinear and are on a plane. // Returns true if the given 3D points are non-collinear and are on a plane.
@ -765,6 +765,7 @@ function plane_line_angle(plane, line) =
// Given a plane definition `[A,B,C,D]`, where `Ax+By+Cz=D`, and a list of 2d or // Given a plane definition `[A,B,C,D]`, where `Ax+By+Cz=D`, and a list of 2d or
// 3d points, return the closest 3D orthogonal projection of the points on the plane. // 3d points, return the closest 3D orthogonal projection of the points on the plane.
// In other words, for every point given, returns the closest point to it on the plane. // In other words, for every point given, returns the closest point to it on the plane.
// If points is a single point then returns a single point result.
// Arguments: // Arguments:
// plane = The `[A,B,C,D]` plane definition where `Ax+By+Cz=D` is the formula of the plane. // plane = The `[A,B,C,D]` plane definition where `Ax+By+Cz=D` is the formula of the plane.
// points = List of points to project // points = List of points to project
@ -824,7 +825,7 @@ function _pointlist_greatest_distance(points,plane) =
// Function: are_points_on_plane() // Function: are_points_on_plane()
// Usage: // Usage:
// test = are_points_on_plane(points, plane, [eps]); // bool = are_points_on_plane(points, plane, [eps]);
// Topics: Geometry, Planes, Points // Topics: Geometry, Planes, Points
// Description: // Description:
// Returns true if the given 3D points are on the given plane. // Returns true if the given 3D points are on the given plane.
@ -841,7 +842,7 @@ function are_points_on_plane(points, plane, eps=EPSILON) =
/// Internal Function: is_point_above_plane() /// Internal Function: is_point_above_plane()
/// Usage: /// Usage:
/// test = _is_point_above_plane(plane, point); /// bool = _is_point_above_plane(plane, point);
/// Topics: Geometry, Planes /// Topics: Geometry, Planes
// Description: // Description:
/// Given a plane as [A,B,C,D] where the cartesian equation for that plane /// Given a plane as [A,B,C,D] where the cartesian equation for that plane
@ -860,7 +861,7 @@ function _is_point_above_plane(plane, point) =
// Function: circle_line_intersection() // Function: circle_line_intersection()
// Usage: // Usage:
// isect = circle_line_intersection(c,<r|d>,[line],[bounded],[eps]); // isect = circle_line_intersection(c, r|d=, line, [bounded], [eps=]);
// Topics: Geometry, Circles, Lines, Intersection // Topics: Geometry, Circles, Lines, Intersection
// Description: // Description:
// Find intersection points between a 2d circle and a line, ray or segment specified by two points. // Find intersection points between a 2d circle and a line, ray or segment specified by two points.
@ -903,7 +904,7 @@ function _circle_or_sphere_line_intersection(c,r,line,bounded=false,d,eps=EPSILO
// Function: circle_circle_intersection() // Function: circle_circle_intersection()
// Usage: // Usage:
// pts = circle_circle_tangents(c1, r1|d1, c2, r2|d2, [eps]); // pts = circle_circle_tangents(c1, r1|d1=, c2, r2|d2=, [eps]);
// Topics: Geometry, Circles // Topics: Geometry, Circles
// Description: // Description:
// Compute the intersection points of two circles. Returns a list of the intersection points, which // Compute the intersection points of two circles. Returns a list of the intersection points, which
@ -969,10 +970,10 @@ function circle_circle_intersection(c1,r1,c2,r2,eps=EPSILON,d1,d2) =
// Function&Module: circle_2tangents() // Function&Module: circle_2tangents()
// Usage: As Function // Usage: As Function
// circ = circle_2tangents(pt1, pt2, pt3, r|d, [tangents]); // circ = circle_2tangents(pt1, pt2, pt3, r|d=, [tangents=]);
// Topics: Geometry, Circles, Tangents // Topics: Geometry, Circles, Tangents
// Usage: As Module // Usage: As Module
// circle_2tangents(pt1, pt2, pt3, r|d, [h], [center]); // circle_2tangents(pt1, pt2, pt3, r|d=, [h=], [center=]);
// Description: // Description:
// Given a pair of rays with a common origin, and a known circle radius/diameter, finds // Given a pair of rays with a common origin, and a known circle radius/diameter, finds
// the centerpoint for the circle of that size that touches both rays tangentally. // the centerpoint for the circle of that size that touches both rays tangentally.
@ -998,6 +999,7 @@ function circle_circle_intersection(c1,r1,c2,r2,eps=EPSILON,d1,d2) =
// pt2 = The starting point of both rays. // pt2 = The starting point of both rays.
// pt3 = A point that the second ray passes though. // pt3 = A point that the second ray passes though.
// r = The radius of the circle to find. // r = The radius of the circle to find.
// ---
// d = The diameter of the circle to find. // d = The diameter of the circle to find.
// h = Height of the cylinder to create, when called as a module. // h = Height of the cylinder to create, when called as a module.
// center = When called as a module, center the cylinder if true, Default: false // center = When called as a module, center the cylinder if true, Default: false
@ -1063,6 +1065,7 @@ function circle_2tangents(pt1, pt2, pt3, r, d, tangents=false) =
module circle_2tangents(pt1, pt2, pt3, r, d, h, center=false) { module circle_2tangents(pt1, pt2, pt3, r, d, h, center=false) {
no_children($children);
c = circle_2tangents(pt1=pt1, pt2=pt2, pt3=pt3, r=r, d=d); c = circle_2tangents(pt1=pt1, pt2=pt2, pt3=pt3, r=r, d=d);
assert(!is_undef(c), "Cannot find circle when both rays are collinear."); assert(!is_undef(c), "Cannot find circle when both rays are collinear.");
cp = c[0]; n = c[1]; cp = c[0]; n = c[1];
@ -1147,6 +1150,7 @@ function circle_3points(pt1, pt2, pt3) =
module circle_3points(pt1, pt2, pt3, h, center=false) { module circle_3points(pt1, pt2, pt3, h, center=false) {
no_children($children);
c = circle_3points(pt1, pt2, pt3); c = circle_3points(pt1, pt2, pt3);
assert(!is_undef(c[0]), "Points cannot be collinear."); assert(!is_undef(c[0]), "Points cannot be collinear.");
cp = c[0]; r = c[1]; n = c[2]; cp = c[0]; r = c[1]; n = c[2];
@ -1161,16 +1165,17 @@ module circle_3points(pt1, pt2, pt3, h, center=false) {
// Function: circle_point_tangents() // Function: circle_point_tangents()
// Usage: // Usage:
// tangents = circle_point_tangents(r|d, cp, pt); // tangents = circle_point_tangents(r|d=, cp, pt);
// Topics: Geometry, Circles, Tangents // Topics: Geometry, Circles, Tangents
// Description: // Description:
// Given a 2d circle and a 2d point outside that circle, finds the 2d tangent point(s) on the circle for a // Given a 2d circle and a 2d point outside that circle, finds the 2d tangent point(s) on the circle for a
// line passing through the point. Returns a list of zero or more 2D tangent points. // line passing through the point. Returns a list of zero or more 2D tangent points.
// Arguments: // Arguments:
// r = Radius of the circle. // r = Radius of the circle.
// d = Diameter of the circle.
// cp = The coordinates of the 2d circle centerpoint. // cp = The coordinates of the 2d circle centerpoint.
// pt = The coordinates of the 2d external point. // pt = The coordinates of the 2d external point.
// ---
// d = Diameter of the circle.
// Example(3D): // Example(3D):
// cp = [-10,-10]; r = 30; pt = [30,10]; // cp = [-10,-10]; r = 30; pt = [30,10];
// tanpts = circle_point_tangents(r=r, cp=cp, pt=pt); // tanpts = circle_point_tangents(r=r, cp=cp, pt=pt);
@ -1178,7 +1183,7 @@ module circle_3points(pt1, pt2, pt3, h, center=false) {
// color("cyan") for(tp=tanpts) {stroke([tp,pt]); stroke([tp,cp]);} // color("cyan") for(tp=tanpts) {stroke([tp,pt]); stroke([tp,cp]);}
// color("red") move_copies(tanpts) circle(d=3,$fn=12); // color("red") move_copies(tanpts) circle(d=3,$fn=12);
// color("blue") move_copies([cp,pt]) circle(d=3,$fn=12); // color("blue") move_copies([cp,pt]) circle(d=3,$fn=12);
function circle_point_tangents(r, d, cp, pt) = function circle_point_tangents(r, cp, pt, d) =
assert(is_finite(r) || is_finite(d), "Invalid radius or diameter." ) assert(is_finite(r) || is_finite(d), "Invalid radius or diameter." )
assert(is_path([cp, pt],dim=2), "Invalid center point or external point.") assert(is_path([cp, pt],dim=2), "Invalid center point or external point.")
let( let(
@ -1196,7 +1201,7 @@ function circle_point_tangents(r, d, cp, pt) =
// Function: circle_circle_tangents() // Function: circle_circle_tangents()
// Usage: // Usage:
// segs = circle_circle_tangents(c1, r1|d1, c2, r2|d2); // segs = circle_circle_tangents(c1, r1|d1=, c2, r2|d2=);
// Topics: Geometry, Circles, Tangents // Topics: Geometry, Circles, Tangents
// Description: // Description:
// Computes 2d lines tangents to a pair of circles in 2d. Returns a list of line endpoints [p1,p2] where // Computes 2d lines tangents to a pair of circles in 2d. Returns a list of line endpoints [p1,p2] where
@ -1281,7 +1286,7 @@ function circle_circle_tangents(c1,r1,c2,r2,d1,d2) =
/// Internal Function: _noncollinear_triple() /// Internal Function: _noncollinear_triple()
/// Usage: /// Usage:
/// test = _noncollinear_triple(points); /// bool = _noncollinear_triple(points);
/// Topics: Geometry, Noncollinearity /// Topics: Geometry, Noncollinearity
/// Description: /// Description:
/// Finds the indices of three non-collinear points from the pointlist `points`. /// Finds the indices of three non-collinear points from the pointlist `points`.
@ -1319,11 +1324,9 @@ function _noncollinear_triple(points,error=true,eps=EPSILON) =
// Section: Sphere Calculations // Section: Sphere Calculations
// Function: sphere_line_intersection() // Function: sphere_line_intersection()
// Usage: // Usage:
// isect = sphere_line_intersection(c,<r|d>,[line],[bounded],[eps]); // isect = sphere_line_intersection(c,r|d=,line,[bounded],[eps=]);
// Topics: Geometry, Spheres, Lines, Intersection // Topics: Geometry, Spheres, Lines, Intersection
// Description: // Description:
// Find intersection points between a sphere and a line, ray or segment specified by two points. // Find intersection points between a sphere and a line, ray or segment specified by two points.
@ -1348,7 +1351,7 @@ function sphere_line_intersection(c,r,line,bounded=false,d,eps=EPSILON) =
// Function: polygon_area() // Function: polygon_area()
// Usage: // Usage:
// area = polygon_area(poly); // area = polygon_area(poly, [signed]);
// Topics: Geometry, Polygons, Area // Topics: Geometry, Polygons, Area
// Description: // Description:
// Given a 2D or 3D simple planar polygon, returns the area of that polygon. // Given a 2D or 3D simple planar polygon, returns the area of that polygon.
@ -1474,7 +1477,7 @@ function polygon_normal(poly) =
// Function: point_in_polygon() // Function: point_in_polygon()
// Usage: // Usage:
// test = point_in_polygon(point, poly, [nonzero], [eps]) // bool = point_in_polygon(point, poly, [nonzero], [eps])
// Topics: Geometry, Polygons // Topics: Geometry, Polygons
// Description: // Description:
// This function tests whether the given 2D point is inside, outside or on the boundary of // This function tests whether the given 2D point is inside, outside or on the boundary of
@ -1832,7 +1835,7 @@ function _merge_segments(insegs,outsegs, eps, i=1) =
// report an error for this case. // report an error for this case.
// Arguments: // Arguments:
// poly = Array of the polygon vertices. // poly = Array of the polygon vertices.
// ind = A list indexing the vertices of the polygon in `poly`. // ind = If given, a list of indices indexing the vertices of the polygon in `poly`. Default: use all the points of poly
// error = If false, returns `undef` when the polygon cannot be triangulated; otherwise, issues an assert error. Default: true. // error = If false, returns `undef` when the polygon cannot be triangulated; otherwise, issues an assert error. Default: true.
// eps = A maximum tolerance in geometrical tests. Default: EPSILON // eps = A maximum tolerance in geometrical tests. Default: EPSILON
// Example(2D,NoAxes): a simple polygon; see from above // Example(2D,NoAxes): a simple polygon; see from above
@ -1991,7 +1994,7 @@ function _none_inside(idxs,poly,p0,p1,p2,eps,i=0) =
// Function: is_polygon_clockwise() // Function: is_polygon_clockwise()
// Usage: // Usage:
// test = is_polygon_clockwise(poly); // bool = is_polygon_clockwise(poly);
// Topics: Geometry, Polygons, Clockwise // Topics: Geometry, Polygons, Clockwise
// See Also: clockwise_polygon(), ccw_polygon(), reverse_polygon() // See Also: clockwise_polygon(), ccw_polygon(), reverse_polygon()
// Description: // Description:
@ -2181,7 +2184,7 @@ function align_polygon(reference, poly, angles, cp, trans, return_ind=false) =
// Function: are_polygons_equal() // Function: are_polygons_equal()
// Usage: // Usage:
// b = are_polygons_equal(poly1, poly2, [eps]) // bool = are_polygons_equal(poly1, poly2, [eps])
// Description: // Description:
// Returns true if poly1 and poly2 are the same polongs // Returns true if poly1 and poly2 are the same polongs
// within given epsilon tolerance. // within given epsilon tolerance.
@ -2236,7 +2239,7 @@ function ___is_polygon_in_list(poly, polys, i) =
// Function: hull() // Function: hull()
// Usage: // Usage:
// hull(points); // face_list_or_index_list = hull(points);
// Description: // Description:
// Takes a list of 2D or 3D points (but not both in the same list) and returns either the list of // Takes a list of 2D or 3D points (but not both in the same list) and returns either the list of
// indexes into `points` that forms the 2D convex hull perimeter path, or the list of faces that // indexes into `points` that forms the 2D convex hull perimeter path, or the list of faces that
@ -2272,6 +2275,7 @@ function hull(points) =
// pts = [for (phi = [30:60:150], theta = [0:60:359]) spherical_to_xyz(10, theta, phi)]; // pts = [for (phi = [30:60:150], theta = [0:60:359]) spherical_to_xyz(10, theta, phi)];
// hull_points(pts); // hull_points(pts);
module hull_points(points, fast=false) { module hull_points(points, fast=false) {
no_children($children);
assert(is_path(points)) assert(is_path(points))
assert(len(points)>=3, "Point list must contain 3 points") assert(len(points)>=3, "Point list must contain 3 points")
if (len(points[0])==2) if (len(points[0])==2)
@ -2309,7 +2313,7 @@ function _is_cw(a,b,c,all) =
// Function: hull2d_path() // Function: hull2d_path()
// Usage: // Usage:
// hull2d_path(points,all) // index_list = hull2d_path(points,all)
// Description: // Description:
// Takes a list of arbitrary 2D points, and finds the convex hull polygon to enclose them. // Takes a list of arbitrary 2D points, and finds the convex hull polygon to enclose them.
// Returns a path as a list of indices into `points`. // Returns a path as a list of indices into `points`.
@ -2371,7 +2375,7 @@ function _hull_collinear(points) =
// Function: hull3d_faces() // Function: hull3d_faces()
// Usage: // Usage:
// hull3d_faces(points) // faces = hull3d_faces(points)
// Description: // Description:
// Takes a list of arbitrary 3D points, and finds the convex hull polyhedron to enclose // Takes a list of arbitrary 3D points, and finds the convex hull polyhedron to enclose
// them. Returns a list of triangular faces, where each face is a list of indexes into the given `points` // them. Returns a list of triangular faces, where each face is a list of indexes into the given `points`
@ -2482,7 +2486,7 @@ function _find_first_noncoplanar(plane, points, i=0) =
// Function: is_polygon_convex() // Function: is_polygon_convex()
// Usage: // Usage:
// test = is_polygon_convex(poly); // bool = is_polygon_convex(poly, [eps]);
// Topics: Geometry, Convexity, Test // Topics: Geometry, Convexity, Test
// Description: // Description:
// Returns true if the given 2D or 3D polygon is convex. // Returns true if the given 2D or 3D polygon is convex.
@ -2527,7 +2531,7 @@ function is_polygon_convex(poly,eps=EPSILON) =
// Function: convex_distance() // Function: convex_distance()
// Usage: // Usage:
// dist = convex_distance(pts1, pts2,[eps=]); // dist = convex_distance(points1, points2,eps);
// Topics: Geometry, Convexity, Distance // Topics: Geometry, Convexity, Distance
// See also: // See also:
// convex_collision(), hull() // convex_collision(), hull()
@ -2586,7 +2590,7 @@ function _GJK_distance(points1, points2, eps=EPSILON, lbd, d, simplex=[]) =
// Function: convex_collision() // Function: convex_collision()
// Usage: // Usage:
// test = convex_collision(pts1, pts2, [eps=]); // bool = convex_collision(points1, points2, [eps]);
// Topics: Geometry, Convexity, Collision, Intersection // Topics: Geometry, Convexity, Collision, Intersection
// See also: // See also:
// convex_distance(), hull() // convex_distance(), hull()