[Math] Find control point on piecewise quadratic Bézier curve

bezier-curvegeometry

I need to write an OpenGL program to generate and display a piecewise quadratic Bézier curve that interpolates each set of data points:

$$(0.1, 0), (0, 0), (0, 5), (0.25, 5), (0.25, 0), (5, 0), (5, 5), (10, 5), (10, 0), (9.5, 0)$$

The curve should have continuous tangent directions, the tangent direction at each data point being a convex combination of the two adjacent chord directions.

I am not good at math, can anyone give me some suggestions about what formula I can use to calculate control point for Bézier curve if I have a starting point and an ending point.

Thanks in advance

Best Answer

You can see that it will be difficult to solve this satisfactorily by considering the case where the points to be interpolated are at the extrema of a sinusoidal curve. Any reasonable solution should have horizontal tangents at the points, but this is not possible with quadratic curves.

Peter has described how to achieve continuity of the tangents with many arbitrary choices. You can reduce those choices to a single choice by requiring continuity in the derivatives, not just their directions (which determine the tangents). This looks nice formally, but it can lead to rather wild curves, since a single choice of control point at one end then determines all the control points (since you now have to take equal steps on both sides of the points in Peter's method), and these may end up quite far away from the original points – again, take the case of the extrema of a sinusoidal; this will cause the control points to oscillate more and more as you propagate them.

What I would try in order to get around these problems, if you really have to use quadratic Bézier curves, is to use some good interpolation method, e.g. cubic splines, and calculate intermediate points between the given points, along with tangent directions at the given points and the intermediate points. Then you can draw quadratic Bézier curves through all the points, given and intermediate, and determine control points by intersecting the tangents. This wouldn't work without the intermediate points, because the tangents might not intersect at reasonable points – again, think of the extrema of a sinuisoidal, where the desired tangents are in fact parallel – but I think it should work with the intermediate points – for instance, in the sinusoidal example, the intermediate points would be at the inflection points of the sinusoidal, and the tangents would intersect at suitable control points.