0

Checking if two cubic Bézier curves intersect gives a link to http://cagd.cs.byu.edu/~557/text/ch7.pdf .. sounds readable on first pass.. but it is not code.

I am wondering if someone has actually implemented this algorithm in any common programming language. I would be interested in some Javascript code (other languages OK) that can implement the algorithm using two cubic Bézier curves, or a Bézier curve and a straight line.

Community
  • 1
  • 1
Agamemnus
  • 1,395
  • 4
  • 17
  • 41
  • If you're asking about a specific algorithm, it'd be a good idea to mention which one in the title/post (the linked chapter contains more than one). The subdivision algorithm is implemented over at http://pomax.github.io/bezierinfo/#curveintersection – Mike 'Pomax' Kamermans Jul 20 '14 at 06:09

1 Answers1

0

For a cubic Bézier curves and a straight line it probably easiest to use section 7.3 Intersection of a Parametric Curve and an Implicit Curve. You can write the straight line as a x+b y+c=0. If you Bézier curves in given by cubic p(t) and q(t) for x and y coords you can substitute those into the line equation. This gives a cubic in t which you can solve by your favourite root finding algorithm.

The similar question Checking if two cubic Bézier curves intersect has some good answers. In particular the first answer mentions the asymptote library which has code for all these. You can see the relevant source code at http://sourceforge.net/p/asymptote/code/HEAD/tree/trunk/asymptote/path.cc including code for finding roots of a cubic.

Community
  • 1
  • 1
Salix alba
  • 7,536
  • 2
  • 32
  • 38