mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
fix find_noncollinear_points
This commit is contained in:
parent
65125ed57a
commit
3c9e304675
1 changed files with 27 additions and 8 deletions
|
@ -1359,21 +1359,40 @@ function first_noncollinear(i1, i2, points) =
|
||||||
// find_noncollinear_points(points);
|
// find_noncollinear_points(points);
|
||||||
// Description:
|
// Description:
|
||||||
// Finds the indices of three good non-collinear points from the points list `points`.
|
// Finds the indices of three good non-collinear points from the points list `points`.
|
||||||
function find_noncollinear_points(points) =
|
function find_noncollinear_points(points,error=true,eps=EPSILON) =
|
||||||
|
let(
|
||||||
|
pa = points[0],
|
||||||
|
b = furthest_point(pa, points),
|
||||||
|
n = unit(points[b]-pa),
|
||||||
|
relpoints = [for(pt=points) pt-pa],
|
||||||
|
proj = relpoints * n,
|
||||||
|
distlist = [for(i=[0:len(points)-1]) norm(relpoints[i]-proj[i]*n)]
|
||||||
|
)
|
||||||
|
max(distlist)<eps
|
||||||
|
? assert(!error, "Cannot find three noncollinear points in pointlist.")
|
||||||
|
[]
|
||||||
|
: [0,b,max_index(distlist)];
|
||||||
|
|
||||||
|
function old_find_noncollinear_points(points,error=true) =
|
||||||
let(
|
let(
|
||||||
a = 0,
|
a = 0,
|
||||||
b = furthest_point(points[a], points),
|
b = furthest_point(points[a], points),
|
||||||
pa = points[a],
|
pa = points[a],
|
||||||
pb = points[b],
|
pb = points[b],
|
||||||
c = max_index([
|
c = max_index([
|
||||||
for (p=points)
|
for (p=points)
|
||||||
(approx(p,pa) || approx(p,pb))? 0 :
|
(approx(p,pa) || approx(p,pb))? 0 :
|
||||||
sin(vector_angle(points[a]-p,points[b]-p)) *
|
let(score =
|
||||||
norm(p-points[a]) * norm(p-points[b])
|
sin(vector_angle(points[a]-p,points[b]-p)) *
|
||||||
])
|
norm(p-points[a]) * norm(p-points[b]),fff=echo(score=score))
|
||||||
)
|
approx(score,0,eps=1e-7) ? -1 : score])
|
||||||
assert(c!=a && c!=b, "Cannot find three noncollinear points in pointlist.")
|
,foo=echo(pval = a,b,c)
|
||||||
[a, b, c];
|
)
|
||||||
|
|
||||||
|
c ==a || c==b
|
||||||
|
? assert(!error, "Cannot find three noncollinear points in pointlist.")
|
||||||
|
[]
|
||||||
|
: [a, b, c];
|
||||||
|
|
||||||
|
|
||||||
// Function: pointlist_bounds()
|
// Function: pointlist_bounds()
|
||||||
|
|
Loading…
Reference in a new issue