Revert "correction of centroid"

This reverts commit d4c7fab7ed.
This commit is contained in:
RonaldoCMP 2021-04-05 16:00:07 +01:00
parent 2c03b19246
commit 8c0e389ec4
2 changed files with 26 additions and 23 deletions

View file

@ -959,7 +959,7 @@ function plane_from_polygon(poly, fast=false, eps=EPSILON) =
// plane_normal(plane);
// Description:
// Returns the unit length normal vector for the given plane.
// Arguments:
// Argument:
// plane = The `[A,B,C,D]` plane definition where `Ax+By+Cz=D` is the formula of the plane.
function plane_normal(plane) =
assert( _valid_plane(plane), "Invalid input plane." )
@ -973,7 +973,7 @@ function plane_normal(plane) =
// Returns coeficient D of the normalized plane equation `Ax+By+Cz=D`, or the scalar offset of the plane from the origin.
// This value may be negative.
// The absolute value of this coefficient is the distance of the plane from the origin.
// Arguments:
// Argument:
// plane = The `[A,B,C,D]` plane definition where `Ax+By+Cz=D` is the formula of the plane.
function plane_offset(plane) =
assert( _valid_plane(plane), "Invalid input plane." )
@ -1046,7 +1046,7 @@ function projection_on_plane(plane, points) =
// pt = plane_point_nearest_origin(plane);
// Description:
// Returns the point on the plane that is closest to the origin.
// Arguments:
// Argument:
// plane = The `[A,B,C,D]` plane definition where `Ax+By+Cz=D` is the formula of the plane.
function plane_point_nearest_origin(plane) =
let( plane = normalize_plane(plane) )
@ -1072,7 +1072,6 @@ function distance_from_plane(plane, point) =
let( plane = normalize_plane(plane) )
point3d(plane)* point - plane[3];
// Returns [POINT, U] if line intersects plane at one point.
// Returns [LINE, undef] if the line is on the plane.
// Returns undef if line is parallel to, but not on the given plane.
@ -1595,6 +1594,7 @@ function circle_circle_tangents(c1,r1,c2,r2,d1,d2) =
];
// Function: circle_line_intersection()
// Usage:
// isect = circle_line_intersection(c,r,line,<bounded>,<eps>);
@ -1627,6 +1627,7 @@ function circle_line_intersection(c,r,line,d,bounded=false,eps=EPSILON) =
let( offset = sqrt(r*r-d*d),
uvec=unit(line[1]-line[0])
) [closest-offset*uvec, closest+offset*uvec]
)
[for(p=isect)
if ((!bounded[0] || (p-line[0])*(line[1]-line[0])>=0)
@ -1634,6 +1635,7 @@ function circle_line_intersection(c,r,line,d,bounded=false,eps=EPSILON) =
// Section: Pointlists
@ -1913,7 +1915,8 @@ function centroid(poly, eps=EPSILON) =
assert( is_finite(eps) && (eps>=0), "The tolerance should be a non-negative value." )
let(
n = len(poly[0])==2 ? 1 :
let( plane = plane_from_points(poly, fast=true) )
let(
plane = plane_from_points(poly, fast=true) )
assert( !is_undef(plane), "The polygon must be planar." )
plane_normal(plane),
v0 = poly[0] ,