Path stroke algorithm (convert to triangles/quads)

2019-06-17 06:08发布

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.

2条回答
戒情不戒烟
2楼-- · 2019-06-17 06:31

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

查看更多
\"骚年 ilove
3楼-- · 2019-06-17 06:49

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.

查看更多
登录 后发表回答