16

By stroke of the cubic bezier curve I mean rendering a curve 'A' with a specific line width 'w'.

How can I derive other cubic bezier curves that describe the outline of the stroke of bezier 'A' ?

4

3 回答 3

17

Ohhh. You want to get the offset-curves of an bezier curve.

Bad news. this is hard because these curves can't be simply derived numerical. They contain all kinds of intersections, loops and other nasty stuff.

There are some approximations though. The best approach I've read so far is from a paper by Thomas F. Hain (Fast, Precise Flattening of Cubic Bézier Path and Offset Curves).

He does flattening, so his paper is mostly about decomposes the offset curves into line-segments and circular arc-segments, but you can merge them back to beziers later.

For better understanding you may want to read his other bezier related papers as well.

于 2009-01-03T02:18:19.960 回答
4

Qt 的 QPainterPathStroker(它是开源且可读性强的代码)使用上述论文中描述的算法来做你想做的事。

于 2010-06-01T15:33:37.490 回答
1

要准确地做到正如其他人所解释的那样非常困难。偏移曲线不是三次贝塞尔曲线,非常难以处理。然后,比偏移更深的凹面会导致相交问题。

好消息是,通常您要计算笔画偏移以进行渲染,因此只需要像素精度。此外,如果您遵守多边形填充的缠绕规则,则各种交叉点仍会创建填充多边形。所以你先把曲线弄平,然后以线性方式偏移,它就变成了一个直线多边形问题。

这里的一些代码可以作为参考实现: https ://github.com/memononen/nanosvg

于 2017-08-20T20:11:58.473 回答