Wednesday, December 27, 2006

Elliptic arcs and some more pron

So far the hardest problem to solve turned out to be how to parametrise arcs. There are three obvious parameters, namely a control triangle of the rational quadratic bezier that is the arc. But how to get a weight for the middle point?

After playing with different parametrisation, I currently have one which gives the middle point the weight of cos(angle/2) where angle is an extra parameter to the function. It happens that when the legs of the control triangle are of equal length, and the angle between them is supplied as angle, one gets an arc of a circle. When the legs aren't of equal length, or the parameter isn't the angle between the legs, one gets an ellipse instead. For zero angle one gets normal non-rational bezier, and for angle pi one gets a straight line. Larger angles give the other side of the ellipse or circle.

Bonus benefit is that when the curve is subdivided in the middle, one doesn't need to track weights for the control points. Just using half the angle will give the proper midpoint weight.

For the typical uses of arcs, there's an extra function which simply makes the guess that the angle between the legs will probably be fine. For stuff like corners of polyline strokes or rectangles this seems to be a reasonable value.

And naturally we have a sample picture:



In the picture you see 3 elliptic arcs, one line and one cubic bezier.

No comments: