Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the mathematical function defining a bezier curve

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

like image 419
Mizipzor Avatar asked Dec 05 '09 22:12

Mizipzor


1 Answers

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

like image 169
Josef Grahn Avatar answered Sep 30 '22 18:09

Josef Grahn