polyline approximation of a spline edge

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


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


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.

Recent comments