mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-13 21:34:17 +02:00
correction of centroid
This commit is contained in:
@@ -959,7 +959,7 @@ function plane_from_polygon(poly, fast=false, eps=EPSILON) =
|
|||||||
// plane_normal(plane);
|
// plane_normal(plane);
|
||||||
// Description:
|
// Description:
|
||||||
// Returns the unit length normal vector for the given plane.
|
// Returns the unit length normal vector for the given plane.
|
||||||
// Argument:
|
// 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.
|
||||||
function plane_normal(plane) =
|
function plane_normal(plane) =
|
||||||
assert( _valid_plane(plane), "Invalid input 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.
|
// 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.
|
// This value may be negative.
|
||||||
// The absolute value of this coefficient is the distance of the plane from the origin.
|
// The absolute value of this coefficient is the distance of the plane from the origin.
|
||||||
// Argument:
|
// 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.
|
||||||
function plane_offset(plane) =
|
function plane_offset(plane) =
|
||||||
assert( _valid_plane(plane), "Invalid input plane." )
|
assert( _valid_plane(plane), "Invalid input plane." )
|
||||||
@@ -1046,7 +1046,7 @@ function projection_on_plane(plane, points) =
|
|||||||
// pt = plane_point_nearest_origin(plane);
|
// pt = plane_point_nearest_origin(plane);
|
||||||
// Description:
|
// Description:
|
||||||
// Returns the point on the plane that is closest to the origin.
|
// Returns the point on the plane that is closest to the origin.
|
||||||
// Argument:
|
// 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.
|
||||||
function plane_point_nearest_origin(plane) =
|
function plane_point_nearest_origin(plane) =
|
||||||
let( plane = normalize_plane(plane) )
|
let( plane = normalize_plane(plane) )
|
||||||
@@ -1072,6 +1072,7 @@ function distance_from_plane(plane, point) =
|
|||||||
let( plane = normalize_plane(plane) )
|
let( plane = normalize_plane(plane) )
|
||||||
point3d(plane)* point - plane[3];
|
point3d(plane)* point - plane[3];
|
||||||
|
|
||||||
|
|
||||||
// Returns [POINT, U] if line intersects plane at one point.
|
// Returns [POINT, U] if line intersects plane at one point.
|
||||||
// Returns [LINE, undef] if the line is on the plane.
|
// Returns [LINE, undef] if the line is on the plane.
|
||||||
// Returns undef if line is parallel to, but not on the given plane.
|
// Returns undef if line is parallel to, but not on the given plane.
|
||||||
@@ -1594,7 +1595,6 @@ function circle_circle_tangents(c1,r1,c2,r2,d1,d2) =
|
|||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Function: circle_line_intersection()
|
// Function: circle_line_intersection()
|
||||||
// Usage:
|
// Usage:
|
||||||
// isect = circle_line_intersection(c,r,line,<bounded>,<eps>);
|
// isect = circle_line_intersection(c,r,line,<bounded>,<eps>);
|
||||||
@@ -1627,7 +1627,6 @@ function circle_line_intersection(c,r,line,d,bounded=false,eps=EPSILON) =
|
|||||||
let( offset = sqrt(r*r-d*d),
|
let( offset = sqrt(r*r-d*d),
|
||||||
uvec=unit(line[1]-line[0])
|
uvec=unit(line[1]-line[0])
|
||||||
) [closest-offset*uvec, closest+offset*uvec]
|
) [closest-offset*uvec, closest+offset*uvec]
|
||||||
|
|
||||||
)
|
)
|
||||||
[for(p=isect)
|
[for(p=isect)
|
||||||
if ((!bounded[0] || (p-line[0])*(line[1]-line[0])>=0)
|
if ((!bounded[0] || (p-line[0])*(line[1]-line[0])>=0)
|
||||||
@@ -1635,7 +1634,6 @@ function circle_line_intersection(c,r,line,d,bounded=false,eps=EPSILON) =
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Section: Pointlists
|
// Section: Pointlists
|
||||||
|
|
||||||
|
|
||||||
@@ -1915,8 +1913,7 @@ function centroid(poly, eps=EPSILON) =
|
|||||||
assert( is_finite(eps) && (eps>=0), "The tolerance should be a non-negative value." )
|
assert( is_finite(eps) && (eps>=0), "The tolerance should be a non-negative value." )
|
||||||
let(
|
let(
|
||||||
n = len(poly[0])==2 ? 1 :
|
n = len(poly[0])==2 ? 1 :
|
||||||
let(
|
let( plane = plane_from_points(poly, fast=true) )
|
||||||
plane = plane_from_points(poly, fast=true) )
|
|
||||||
assert( !is_undef(plane), "The polygon must be planar." )
|
assert( !is_undef(plane), "The polygon must be planar." )
|
||||||
plane_normal(plane),
|
plane_normal(plane),
|
||||||
v0 = poly[0] ,
|
v0 = poly[0] ,
|
||||||
|
Reference in New Issue
Block a user