Pomax / bezierjs

A nodejs and client-side library for (cubic) Bezier curve work
MIT License
1.7k stars 230 forks source link

The intersection of two identical curves #204

Closed ArtOfOmission closed 11 months ago

ArtOfOmission commented 11 months ago
  var cv1 = new Bezier(48, 84, 100, 187, 166, 37);
  var cv2 = new Bezier(48, 84, 100, 187, 166, 37);

  var icts = cv1.intersects(cv2);
  console.log(icts.length);

These are the same two curves(or one is part of the another), the result has more than 700 intersections. In my project, there should be no intersection, I don't know how to handle it.

Pomax commented 11 months ago

there should be no intersection

There should be infinitely many intersections because literally every point on the first curve is on the second curve as well. You catch this by first checking whether the coordinates are the exact same, before running an intersection call.

ArtOfOmission commented 11 months ago

You are right. Thanks for your reply. I spent a lot of time searching. I found a piece of literature that answered my question The_Study_of_Coincidence_or_Partial_Coincidence_Condition_for_Two_Rational_Cubic_Bezier_Curves