views:

316

answers:

2

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).

A: 

It's fairly well explained in the Wikipedia article in several forms.

wallyk
+3  A: 

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 + B(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 + b(1 - t)t + ct^2

y = d(1 - t)^2 + e(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
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
A, B and C are meant to be two dimensional coordinates, yes. The reuse of B was unintentional.
Josef Grahn