I have a quadratic Bézier curve.

I want to make a path that runs along that curve, whose width is 'w'. (So at any point in time along the exact center of that path, you will be also on the original Bézier curve)

How would I go about calculating two additional quadratic Bézier curves that outline the outer edges of that that path. (where any point on these edges is 'w'/2 distance from the center of the path and the original Bézier curve)?

  • $\begingroup$ The term for this is "offset curve" or "offsetting". This will improve your search results. :-) As mentioned in the answer, this is a non-trivial topic. $\endgroup$ – WimC Jun 2 '12 at 19:39

Just offset the control polygon of the Bezier curve by a distance of $w/2$ in each direction. As others have pointed out, this is an approximation. Position will be correct at 3 points, and the end tangent directions will be correct. Test the deviation from the true offset. If the deviation is too large, divide the original Bezier curve into two, and apply my suggested offsetting technique to the two pieces. Keep subdividing, offsetting and testing until you're happy.

To test the deviation between the approximate offset and the true one, I'd recommend an approach based on point sampling. In other words, measure the deviation at some sample points, and assume that the maximum deviation is the maximum of the deviations at these sample points. This is not really correct, of course, but it will work OK in practice. For quadratic curves, around 10 or 15 sample points is probably enough. So, take 10 points along your offset curve, measure the distance from each of them to the original curve, and compare these measured distances with the desired offset distance.

So, now, the remaining problem is how to measure the distance from a point $Q$ to a Bezier curve $C(t)$. The key is to find the "foot" of the normal from $Q$ to the curve $C$. This normal will be perpendicular to the tangent vector, so, at the "foot" point, we have:

$$(Q - C(t))\cdot C'(t) = 0$$

Use your favorite numerical root-finder to solve for $t$

  • $\begingroup$ Why is it an approximation? A Bézier curve is affine invariant (because the Bernstein basis functions form a partition of unity), so therefore the curve shouldn't change when the control polygon is translated/rotated. Perhaps I'm misinterpreting the question. $\endgroup$ – Ailurus Nov 3 '12 at 13:44
  • $\begingroup$ The OP wants to offset the curve (along its normals), not translate/rotate it. The word "shift" in the title is a bit misleading $\endgroup$ – bubba Nov 19 '12 at 2:16
  • $\begingroup$ @bubba: Could you please suggest a good way how to measure the deviation? $\endgroup$ – Ecir Hana Feb 13 '13 at 12:04
  • $\begingroup$ Not enough space in a comment, so I added some suggestions to my previous answer. $\endgroup$ – bubba Feb 13 '13 at 14:25

Quadratic Bézier curves are always either pieces of parabolas or straight lines.

Unfortunally, the curve at a fixed distance from a parabola is not itself a parabola (consider, for example, the curve on the inside of the parabola at a distance that is longer than the radius of curvature at the parabola's apex), so it cannot be expressed exactly as a quadratic Bézier curve. You will have to resort to approximations.

Here is a somewhat relevant MO question.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.