The Graphviz site will soon be moved to a new host, and have a different format. You can try out the new site here. If you have suggestions or encounter any problems, please send mail to [email protected] |

# polyline approximation of a spline edge

Submitted by kl123 on Fri, 10/10/2014 - 03:01

I'd like to generate a poly-line approximation for the edge spline, given its control points.

How might I do this?

Is there code someone can point me to?

Thanks much

kl123

## Recent comments

- This is a bug that has been

16 weeks 3 days ago - Double edges: even with latest version

16 weeks 3 days ago - If you run dot.exe -V, this

26 weeks 12 hours ago - Not sure

26 weeks 1 day ago - What version of Graphviz are

26 weeks 1 day ago - update

51 weeks 6 days ago - re: yum install - Error downloading packages

1 year 7 weeks ago - yum install - Error downloading packages

1 year 8 weeks ago - Hi,
Sorry, I was a little

1 year 9 weeks ago - The difficulties you are

1 year 13 weeks ago

## thanks, but i need a better

thanks, but i need a better approximation than just the control points.

is the spline modeled as a series of quadratic or cubic bezier curves? i counted the number of spline points (which i assume are bezier control points) in a number of cases but could not conclude. depending on this, i should be able to get my polyline approx by calculating something like the following, i believe:

point-on-spline(t) = P0*(1-t)**3 + 3*P1*t*(1-t)**2 + 3*P2*t**2*(1-t) + P3*t**3, for a cubic spline with control points P0,P1,P2,P3, where t varies from 0.0 to 1.0

is this understanding correct?

thanks much

kl123

## Yes, the splines are modeled

Yes, the splines are modeled as a series of cubic Bezier curves, so splines always contain 3*n+1 control points with the usual interpretation.

## One way is to run the layout

One way is to run the layout with splines=polyline. This polyline is used by Graphviz as the first approximation to the final spline it constructs.

If you have the points of the B-spline, you know the B-spline goes through all of the points p_i where i = 0 mod 3, so you could those poins. Or just use all of the points of the B-spline. None of the Graphviz programs generate this directly; they only provide the first approximation mentioned above or the full spline. If you want another approximation, you will have to postprocess the output using, say, gvpr, to modify the edges' pos attribute. For example, if an edge has

pos="p0 p1 p2 p3 p4 p5 p6"

you can change this into a polyline representation using the points p_i, i = 0 mod 3, by replacing pos with

pos="p0 p0 p3 p3 p3 p6 p6"

Basically, the Bezier with control points p0 p0 p1 p1 is drawn as a line segment from p0 to p1.