1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-08-22 08:13:51 +02:00

circle intersection

This commit is contained in:
Pomax
2020-11-20 17:16:37 -08:00
parent 43973e9bb3
commit 22e7babbb5
89 changed files with 16058 additions and 29539 deletions

View File

@@ -1,3 +1,5 @@
import refineBinary from "./refine-binary.js";
let curve;
setup() {
@@ -61,56 +63,12 @@ showCandidateInterval(x, y, LUT, i) {
}
drawProjection(x, y, LUT, i) {
let B = this.refineBinary(x, y, LUT, i);
let B = refineBinary(curve, x, y, LUT, i);
setColor(`rgba(100,100,255)`);
circle(B.x, B.y, 3);
line(B.x, B.y, x, y);
}
/*
We already know that LUT[i1] and LUT[i2] are *not* good distances,
so we know that a better distance will be somewhere between them.
We generate three new points between those two, so we end up with
five points, and then check which three of those five are a new,
better, interval to check within.
*/
refineBinary(x, y, LUT, i) {
let q, count=1, distance = Number.MAX_SAFE_INTEGER;
do {
let i1 = i === 0 ? 0 : i-1,
i2 = i === LUT.length - 1 ? LUT.length -1 : i+1,
t1 = LUT[i1].t,
t2 = LUT[i2].t,
lut = [],
step = (t2 - t1)/5;
if (step < 0.001) break;
lut.push(LUT[i1]);
for(let j=1; j<=3; j++) {
let n = curve.get(t1 + j *step);
n.distance = dist(n.x, n.y, x, y);
if (n.distance < distance) {
distance = n.distance;
q = n;
i = j;
}
lut.push(n);
}
lut.push(LUT[i2]);
// update the LUT to be our new five point LUT, and run again.
LUT = lut;
// The "count" test is mostly a safety measure: it will
// never kick in, but something that _will_ terminate is
// always better than while(true). Never use while(true)
} while (count++ < 25);
return q;
}
onMouseMove() {
redraw();
}