I have 2 questions about bezier开发者_运维技巧 curves, and using them to approximate portions of circles.
Given the unit circle arc (1,0)->(cos(a),sin(a)) where 0 < a < pi/2, will it result in a good approximation of this arc to find the bezier curve's control points p1, p2 by solving the equations imposed by the requirements B(1/3) = (cos(a/3), sin(a/3)) and B(2/3) = (cos(2a/3), sin(2a/3)). (In other words, requiring that the bezier curve go through two evenly spaced points in the arc).
If we have an affine transformation A which turns the circle arc in an ellipse arc will the transformed control points Ap0, Ap1, Ap2, Ap3 define a good bezier approximation to the ellipse arc?
p0 and p3, of course, are the start and end points of the curve: (1,0) and (cos(a), sin(a)).
Thank you
Here's a general solution for any elliptical arc as a cubic Bezier curve.
The error is most dependent on the difference of the start and end angles. I've had good success by limiting the angle difference to 60°. That is, I make a separate cubic segment for every 60° (or fraction thereof) and chain them together.
Your questions basically ask "are these good approximations for a semicircle/arc of an ellipse".
You might want to try computing B_y(a) - sin(a)
(of course, parameterizing your equations to both end at (-1,0)
at the same value of a
) for your curve B(a)
, on a graphing utility such as Wolfram Alpha to graph it, and see how much the variance is, and whether or not it suits your purposes.
If you want a more precise and non-visual answer, you may calculate
Integral (from 0 to K) [B_y(a) - sin(a)]^2 da / 2
Where K is the value of a
where both parameterized curves end up at (-1,0)
.
This integral is related/proportional (somewhat) to some measure of Standard Deviation, and will serve well as a numerical analysis. If it's within your desired accuracy, you are good.
Your second question, where you mention an affine transformation of a circle to an ellipse, will give you an error proportional to your original error, if your transformation is essentially linear. If not, you could try using the Jacobian Determinant of your transformation to see how the error would vary.
I have also found a nice Analysis of Semicircle-Bezier Approximations where the author finds a pretty sexy approximation:
Given by:
xValueInset = Diameter * 0.05 yValueOffset = radius * 4.0 / 3.0 P0 = (0,0) P1 = (xValueInset, yValueOffset) P2 = (Diameter - xValueInset, yValueOffset) P3 = (Diameter, 0)
Where P1 and P2 are your control points. Note that this approximates the semicircle:
B(a) = [ (d/2)*cos(a)+d/2 , (d/2)*sin(a) ]
精彩评论