You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There seems to be a problem when calculating intersections between a bezier curve and a line, at very specific cases wIth the common thread being that the intersecting line is parallel to the Y axis.
Wrong result:
In the problem cases below, the code returns an empty array (no intersections) even though the curve does intersect with the line.
Side effect:
Another oddity I've noticed -
for the cases when getting incorrect results for .intersects (these that yield incorrect empty result), the .intersects call seems to mutate the curve object by adding another property "t" to the curve's first point.
Example case:
constbzCurve=newBezier({x: 623.0342104670767,y: 427.30684253642517},{x: 359.8595533490565,y: 519.6488274901164},{x: 96.68489623103626,y: 427.3068425364252});constp1={x: 608.0342104670767,y: 443.30684253642517};constp2={x: 608.0342104670767,y: 422.30684253642517};constep=0.00001;console.log(bzCurve.points[0]);// { x: 623.0342104670767, y: 427.30684253642517 }// original line - problem with .intersectsconsole.log('result',bzCurve.intersects({ p1, p2 }));// []// moving one point slightly so the line is not parallel to Y axis, correct resultsconstp1_1={ ...p1,x: p1.x+ep};console.log('result_1',bzCurve.intersects({p1: p1_1, p2 }));// [0.02849817524894296]constp1_2={ ...p1,x: p1.x-ep};console.log('result_2',bzCurve.intersects({p1: p1_2, p2 }));// [0.028498193956362425]// shifting both points, thereby shifting the line slightly - on the X axis. line is again parallel to the Y-axis.// getting incorrect results againconstp2_2={ ...p2,x: p2.x-ep};console.log('result_3',bzCurve.intersects({p1: p1_2,p2: p2_2}));// []// observe - the key "t" was added to the first point on the curve// this property is added only when calling .intersects that returns no intersections.console.log(bzCurve.points[0]);// { x: 623.0342104670767, y: 427.30684253642517, t: 0 });
The text was updated successfully, but these errors were encountered:
Andrey-Gutsy
changed the title
Intersect line method is not always finding intersections
Intersect line method does not always return existing intersections
Aug 7, 2023
might be a different case for the same underlying symptom, so best case one solution fixes both. I finally have a few spares days so I'll be rewriting bezier.js to modern JS instead of something that had to stay IE compatible and hopefully catch this problem at the same time.
I am really happy I came across this repo.
Solved something that was deemed too hard to solve or absolutely not performant with what I managed without it.
Thanks!
There seems to be a problem when calculating intersections between a bezier curve and a line, at very specific cases wIth the common thread being that the intersecting line is parallel to the Y axis.
Wrong result:
In the problem cases below, the code returns an empty array (no intersections) even though the curve does intersect with the line.
Side effect:
Another oddity I've noticed -
for the cases when getting incorrect results for
.intersects
(these that yield incorrect empty result), the.intersects
call seems to mutate the curve object by adding another property "t" to the curve's first point.Example case:
The text was updated successfully, but these errors were encountered: