diff --git a/docs/chapters/curveintersection/curve-curve.js b/docs/chapters/curveintersection/curve-curve.js
index cb374319..ce0de9fd 100644
--- a/docs/chapters/curveintersection/curve-curve.js
+++ b/docs/chapters/curveintersection/curve-curve.js
@@ -56,7 +56,7 @@ draw() {
text(`${this.finals.length} intersections found.`, this.panelWidth/2, this.height - 10, CENTER);
}
- // panel 3: intersections
+ // panel 3: the (already known) intersections
nextPanel();
this.drawIntersections();
}
@@ -73,7 +73,7 @@ drawIteration() {
const s1 = pair[0].split(0.5);
const s2 = pair[1].split(0.5);
- // cross check
+ // cross check to see if we need to keep any of the pairs
if (s1.left.overlaps(s2.left)) { this.pairs.push([ s1.left, s2.left ]); }
if (s1.left.overlaps(s2.right)) { this.pairs.push([ s1.left, s2.right ]); }
if (s1.right.overlaps(s2.left)) { this.pairs.push([ s1.right, s2.left ]); }
@@ -81,10 +81,12 @@ drawIteration() {
});
}
+ // if we have no pairs left, the next button should not be clickable anymore.
if (!this.pairs.length && next) {
next.disabled = true;
}
+ // draw any curves we have in our pairs list
this.pairs.forEach(pair => {
pair.forEach(b => {
let curve = new Bezier(this, b.points);
@@ -93,6 +95,7 @@ drawIteration() {
})
});
+ // and draw any "finals" as established intersections at this point.
setStroke(`red`);
this.finals.forEach(pair => {
let p = pair[0].get(0.5);
diff --git a/docs/chapters/intersections/curve-line.js b/docs/chapters/intersections/curve-line.js
index cb7425e6..73d4dc41 100644
--- a/docs/chapters/intersections/curve-line.js
+++ b/docs/chapters/intersections/curve-line.js
@@ -23,12 +23,15 @@ draw() {
this.drawLine(...line);
+ // To find our intersections, we align the curve to our line,
+ // so that all we need to do now is find the roots for the curve.
const [p1, p2] = line;
const aligned = utils.align(curve.points, {p1,p2});
const nB = new Bezier(this, aligned);
const roots = utils.roots(nB.points);
const coords = roots.map(t => curve.get(t));
+ // done: any roots we find are intersections on our original curve.
if (roots.length) {
roots.forEach((t,i) => {
var p = coords[i];
diff --git a/docs/chapters/intersections/line-line.js b/docs/chapters/intersections/line-line.js
index 5af4f836..5a3a6881 100644
--- a/docs/chapters/intersections/line-line.js
+++ b/docs/chapters/intersections/line-line.js
@@ -1,11 +1,13 @@
let Point = Vector, points = [];
setup() {
- points.push(new Point(50,50));
- points.push(new Point(150,110));
- points.push(new Point(50,250));
- points.push(new Point(170,170));
- setMovable(points);
+ points = [
+ new Point(50,50),
+ new Point(150,110),
+ new Point(50,250),
+ new Point(170,170),
+ ];
+ setMovable(points);
}
draw() {
@@ -16,6 +18,9 @@ draw() {
this.drawLine(p1,p2);
this.drawLine(p3,p4);
+ // compute the line/line intesection: note that this does NOT
+ // mean the line *segments* intersect, just that the lines,
+ // which are infinitely long, intersect.
const p = this.lli(
p1.x, p1.y,
p2.x, p2.y,
@@ -23,6 +28,7 @@ draw() {
p4.x, p4.y
);
+ // if there is an intersection, is that point on both line *segments*?
if (p) {
if (this.onLine(p, p1, p2) && this.onLine(p, p3, p4)) {
setColor(`lime`);
@@ -44,6 +50,7 @@ drawLine(p1, p2) {
circle(p2.x, p2.y, 2);
}
+// The line/line intersection code can be found all over the web.
lli(x1, y1, x2, y2, x3, y3, x4, y4) {
const nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4),
ny = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4),
@@ -52,6 +59,7 @@ lli(x1, y1, x2, y2, x3, y3, x4, y4) {
return { x: nx / d, y: ny / d };
}
+// is point p on the line p1--p2?
onLine(p, p1, p2) {
const mx = min(p1.x, p2.x),
my = min(p1.y, p2.y),
diff --git a/docs/chapters/offsetting/offsetting.js b/docs/chapters/offsetting/offsetting.js
index 506c1d6e..8166c886 100644
--- a/docs/chapters/offsetting/offsetting.js
+++ b/docs/chapters/offsetting/offsetting.js
@@ -17,16 +17,19 @@ draw() {
curve.drawSkeleton();
+ // First, reduce our curves into a set of simple sections
var reduced = this.reduce(curve);
reduced.forEach(c => {
setStroke(randomColor() );
this.drawCurve(c);
circle(c.points[0].x, c.points[0].y, 2);
});
+
var last = reduced.slice(-1)[0];
let p = last.points[3] ?? last.points[2];
circle(p.x, p.y, 3);
+ // then, we can offset each simple curve by projective scaling
setStroke(`#FF000050`);
var offset = curve.offset(this.distance);
offset.forEach(c => {
@@ -38,6 +41,7 @@ draw() {
p = last.points[3] ?? last.points[2];
circle(p.x, p.y, 3);
+ // on both sides, so we need to offset by -distance, too.
setStroke(`#0000FF50`);
var offset = curve.offset(-this.distance);
offset.forEach(c => {
@@ -116,3 +120,5 @@ reduce(curve) {
return pass2;
}
+
+// TODO: duplicate the offset code from utils.js? It's *a lot* of code, though...
diff --git a/docs/chapters/polybezier/poly.js b/docs/chapters/polybezier/poly.js
index eb37c9ab..facdc7eb 100644
--- a/docs/chapters/polybezier/poly.js
+++ b/docs/chapters/polybezier/poly.js
@@ -71,6 +71,9 @@ draw() {
movePointsQuadratic(i, link) {
const l = points.length;
+
+ // Logic for "conventional" moving of an on-curve point,
+ // moving its associated control points, too.
if (link === `conventional` && i%2 === 0) {
let ppl = points[(l+i-3)%l];
let pl = points[(l+i-1)%l];
@@ -91,6 +94,8 @@ movePointsQuadratic(i, link) {
}
}
+ // Moving a control points moves literally every
+ // other control points, too.
if (i%2 === 1) {
let c1 = points[(l+i-2)%l];
let p1 = points[(l+i-1)%l];
@@ -127,6 +132,9 @@ movePointsQuadratic(i, link) {
movePointsCubic(i, link) {
const l = points.length;
+
+ // Logic for "conventional" moving of an on-curve point,
+ // moving its associated control points, too.
if (link === `conventional` && i%3 === 0) {
let left = points[(l+i-1)%l];
left.x += this.cursor.diff.x;
@@ -137,6 +145,7 @@ movePointsCubic(i, link) {
right.y += this.cursor.diff.y;
}
+ // Moving a control points moves the control "across its on-curve point".
if (i%3 > 0) {
let c, p;
if (i%3 === 1) {
diff --git a/docs/chapters/tracing/distance-function.js b/docs/chapters/tracing/distance-function.js
index 6a59ebf6..751ccd48 100644
--- a/docs/chapters/tracing/distance-function.js
+++ b/docs/chapters/tracing/distance-function.js
@@ -28,11 +28,15 @@ draw() {
plotDistanceFunction(w, h, len) {
noFill();
+
+ // There is no way we're capturing the distance function as a nice
+ // easy function, so instead we're going to do the next best thing:
+ // sample the curve at a number of points, and then construct the
+ // function plot as we walk from one sample to the next.
let LUT = curve.getLUT(this.steps * 10);
- let d = 0;
start();
vertex(0,0);
- for(let i=1, e=LUT.length, p1, p2; i
-
+
@@ -3439,7 +3439,7 @@ y = curve.get(t).y
Scripts are disabled. Showing fallback image.
-
+
@@ -3458,7 +3458,7 @@ y = curve.get(t).y
Scripts are disabled. Showing fallback image.
-
+
@@ -3508,7 +3508,7 @@ y = curve.get(t).y
Scripts are disabled. Showing fallback image.
-
+
@@ -3557,7 +3557,7 @@ lli = function(line1, line2):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -3570,7 +3570,7 @@ lli = function(line1, line2):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -3638,7 +3638,7 @@ lli = function(line1, line2):
Scripts are disabled. Showing fallback image.
-
+
@@ -4796,7 +4796,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4810,7 +4810,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4842,7 +4842,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4856,7 +4856,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4885,7 +4885,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4899,7 +4899,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4923,7 +4923,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4937,7 +4937,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -5095,7 +5095,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -5110,7 +5110,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
diff --git a/docs/ja-JP/index.html b/docs/ja-JP/index.html
index 7fffc027..b709d623 100644
--- a/docs/ja-JP/index.html
+++ b/docs/ja-JP/index.html
@@ -33,7 +33,7 @@
-
+
@@ -3275,7 +3275,7 @@ y = curve.get(t).y
Scripts are disabled. Showing fallback image.
-
+
@@ -3294,7 +3294,7 @@ y = curve.get(t).y
Scripts are disabled. Showing fallback image.
-
+
@@ -3344,7 +3344,7 @@ y = curve.get(t).y
Scripts are disabled. Showing fallback image.
-
+
@@ -3393,7 +3393,7 @@ lli = function(line1, line2):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -3406,7 +3406,7 @@ lli = function(line1, line2):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -3474,7 +3474,7 @@ lli = function(line1, line2):
Scripts are disabled. Showing fallback image.
-
+
@@ -4632,7 +4632,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4646,7 +4646,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4678,7 +4678,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4692,7 +4692,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4721,7 +4721,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4735,7 +4735,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4759,7 +4759,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4773,7 +4773,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4931,7 +4931,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4946,7 +4946,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
diff --git a/docs/news/2020-09-18.html b/docs/news/2020-09-18.html
index 3263431a..6e0d4d1d 100644
--- a/docs/news/2020-09-18.html
+++ b/docs/news/2020-09-18.html
@@ -27,7 +27,7 @@
-
+
diff --git a/docs/zh-CN/index.html b/docs/zh-CN/index.html
index 3e496999..a2c095b8 100644
--- a/docs/zh-CN/index.html
+++ b/docs/zh-CN/index.html
@@ -33,7 +33,7 @@
-
+
@@ -3247,7 +3247,7 @@ y = curve.get(t).y
Scripts are disabled. Showing fallback image.
-
+
@@ -3266,7 +3266,7 @@ y = curve.get(t).y
Scripts are disabled. Showing fallback image.
-
+
@@ -3316,7 +3316,7 @@ y = curve.get(t).y
Scripts are disabled. Showing fallback image.
-
+
@@ -3365,7 +3365,7 @@ lli = function(line1, line2):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -3378,7 +3378,7 @@ lli = function(line1, line2):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -3446,7 +3446,7 @@ lli = function(line1, line2):
Scripts are disabled. Showing fallback image.
-
+
@@ -4604,7 +4604,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4618,7 +4618,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4650,7 +4650,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4664,7 +4664,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4693,7 +4693,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4707,7 +4707,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4731,7 +4731,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4745,7 +4745,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4903,7 +4903,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+
@@ -4918,7 +4918,7 @@ for p = 1 to points.length-3 (inclusive):
>
Scripts are disabled. Showing fallback image.
-
+