5

Im trying to implement a bezier curve and line segment intersection test. The closest thing my searching has turned up is to take the bezier curve (lets limit it to three control points for simplicity) find the mathematical function generating that curve and place it on origo. Then, using the function for the line segment as another function and let them be equal and solve the equation.

Many sources state the above solution (unless Ive misunderstood them), my problem is I cant find the way to calculate the mathematical function that generates the bezier curve.

Oh, and please point out if Im completely off track with finding the intersection point(s).

Mizipzor
  • 51,151
  • 22
  • 97
  • 138

1 Answers1

15

A Bezier curve is a parametric function. A quadratic Bezier curve (i.e. three control points) can be expressed as: F(t) = A(1 - t)^2 + 2B(1 - t)t + Ct^2 where A, B and C are points and t goes from zero to one.

This will give you two equations:

x = a(1 - t)^2 + 2b(1 - t)t + ct^2

y = d(1 - t)^2 + 2e(1 - t)t + ft^2

If you add for instance the line equation (y = kx + m) to that, you'll end up with three equations and three unknowns (x, y and t).

Josef Grahn
  • 1,585
  • 9
  • 12
  • The function you defined B(t) seems to include itself in its definition, is this intended? Or are A, B and C two dimensional (at least in my example) coordinates? – Mizipzor Dec 05 '09 at 23:03
  • A, B and C are meant to be two dimensional coordinates, yes. The reuse of B was unintentional. – Josef Grahn Dec 05 '09 at 23:26
  • 1
    was missing a coefficient of 2 on the middle terms. should be: F(t) = A(1 - t)^2 + 2*B(1 - t)t + Ct^2 – zanlok Sep 12 '13 at 07:19
  • 1
    Thank you zanlok, you are of course right. B is meant to be a control point, so the 2 should be explicit. I'm surprised nobody noticed that for almost four years... – Josef Grahn Sep 12 '13 at 15:18