Outline of cubic bezier curve stroke

∥☆過路亽.° 提交于 2019-12-17 15:36:44

问题


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' ?


回答1:


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.




回答2:


Qt's QPainterPathStroker (it's open source and fairly readable code) uses the algorithm described in the aforementioned paper to do what you want.




回答3:


To do is accurately is as others have explained very difficult. The offset curve is not a cubic Bezier and is very intractable. Then concavities that are deeper than the offset cause intersection problems.

The good news is that normally you want to calculate a stroke offset for rendering, so only need pixel accuracy. Also, the various intersections still create a filled polygon, if you observe the winding rule for polygon filling. So you flatten the curve first, then offset in a linear fashion, and it becomes a straight line polygon problem.

Some code here can be used as a reference implementation: https://github.com/memononen/nanosvg



来源:https://stackoverflow.com/questions/408457/outline-of-cubic-bezier-curve-stroke

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!