diff --git a/public/js/webgl-book-shape-lab.js b/public/js/webgl-book-shape-lab.js index 3817ca0..d778774 100644 --- a/public/js/webgl-book-shape-lab.js +++ b/public/js/webgl-book-shape-lab.js @@ -634,7 +634,7 @@ function buildSupportSolvedLine(anchor, target, lowerLine, side, segments, segme let cursor = 0; for (let index = 1; index <= segments; index += 1) { const stepLength = segmentLengths[index - 1]; - const next = nextPointOnSupportPath(support, cursor, points[index - 1], stepLength); + const next = nextPointOnSupportPath(support, cursor, points[index - 1], stepLength, side, target); points.push(next.point); cursor = next.cursor; } @@ -704,7 +704,7 @@ function createMeasuredPath(points) { return { points, lengths, totalLength: lengths[lengths.length - 1] ?? 0 }; } -function nextPointOnSupportPath(support, cursor, previous, segmentLength) { +function nextPointOnSupportPath(support, cursor, previous, segmentLength, side, target) { let segmentIndex = Math.max(0, support.lengths.findIndex((length) => length > cursor) - 1); if (segmentIndex < 0) segmentIndex = support.points.length - 2; let startDistance = cursor; @@ -713,7 +713,7 @@ function nextPointOnSupportPath(support, cursor, previous, segmentLength) { const to = support.points[segmentIndex + 1]; const endDistance = support.lengths[segmentIndex + 1]; const hit = circleSegmentIntersection(previous, from, to, segmentLength); - if (hit !== null) { + if (hit !== null && side * (hit.point.x - previous.x) >= -0.000001) { return { point: hit.point, cursor: THREE.MathUtils.lerp(startDistance, endDistance, hit.t) @@ -723,7 +723,7 @@ function nextPointOnSupportPath(support, cursor, previous, segmentLength) { from = support.points[segmentIndex]; startDistance = support.lengths[segmentIndex]; } - return extendSupportPathEnd(support, previous, segmentLength); + return extendSupportPathEnd(support, previous, segmentLength, side, target); } function pointAtMeasuredPathDistance(support, distance) { @@ -768,10 +768,12 @@ function circleSegmentIntersection(center, from, to, radius) { }; } -function extendSupportPathEnd(support, previous, segmentLength) { +function extendSupportPathEnd(support, previous, segmentLength, side, target) { const last = support.points[support.points.length - 1]; const before = support.points[Math.max(0, support.points.length - 2)]; - const direction = normalizedVector(last.x - before.x, last.y - before.y); + const supportDirection = normalizedVector(last.x - before.x, last.y - before.y); + const targetDirection = normalizedVector(target.x - previous.x, target.y - previous.y); + const direction = side * supportDirection.x >= 0.05 ? supportDirection : targetDirection; const point = { x: previous.x + direction.x * segmentLength, y: previous.y + direction.y * segmentLength diff --git a/public/webgl-book-shape-lab.html b/public/webgl-book-shape-lab.html index 0da28c1..27bf04b 100644 --- a/public/webgl-book-shape-lab.html +++ b/public/webgl-book-shape-lab.html @@ -74,6 +74,6 @@ 0 / 10 - +