Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 276
Pete Avatar asked Aug 11 '11 11:08

Pete


2 Answers

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

like image 80
Mapsy Avatar answered Oct 23 '22 09:10

Mapsy


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.

like image 25
Pete Avatar answered Oct 23 '22 09:10

Pete