Path stroke algorithm (convert to triangles/quads) or other suggestions

有些话、适合烂在心里 提交于 2019-12-07 01:34:28

问题


Does anyone know a good algorithm for converting a vector path into a stroked path that is composed of triangle/quad faces? Ideally with round line joins.

Basically I am trying to draw a thick path that whose colour is based upon a value that varies with the distance along the path. I'm thinking that converting the path to triangles/quads and texture mapping it by providing the distance along the path as a 1d texture coordinate that can then be used to retrieve the colours at the corners of the triangles and interpolate. Any other suggestions on how to do this that won't look terrible and can be anti-aliased would be appreciated.

I'm using AGG for rendering, currently, but I could maybe use an alternative provided it doesn't have too many dependencies. I guess the back-end used for rendering doesn't really matter. Whilst AGG can stroke paths, the VertexSource interface does not allow for additional vertex information other than the x/y coordinates. Additionally getting my colour mapping into the rasterizer doesn't look feasible when using the normal conv_stroke.


回答1:


For anyone looking for a solution to this, I found this useful: https://keithp.com/~keithp/talks/cairo2003.pdf

So you can effectively convolve a regular polygon with the line to generate the mesh. Requires a slightly more complicated algorithm than outlined in the pdf in order to output triangles, but it's not actually too difficult to extend it.

You can also write a custom span generator for AGG along the lines of agg::span_gouraud_rgba but one that effectively does texture mapping instead.




回答2:


Here's another great resource for understanding the mechanics of stroking a path.



来源:https://stackoverflow.com/questions/7025043/path-stroke-algorithm-convert-to-triangles-quads-or-other-suggestions

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