When drawing an Arc in 2D, using a Bezier Curve approximation, how does one calculate the two control points given that you have a center point of a circle, a start and end angle and a radius?
相关问题
- Direct2D Only Partially Linking in C++ Builder
- d3.js moving average with previous and next data v
- How to get a fixed number of evenly spaced points
- Check if a number is a perfect power of another nu
- How to determine +/- sign when calculating diagona
相关文章
- ceil conterpart for Math.floorDiv in Java?
- why 48 bit seed in util Random class?
- Algorithm for partially filling a polygonal mesh
- Robust polygon normal calculation
- Algorithm for maximizing coverage of rectangular a
- Behavior of uniforms after glUseProgram() and spee
- Need help generating discrete random numbers from
- How do you create a formula that has diminishing r
Raphael 2.1.0 has support for Arc->Cubic (path2curve-function), and after fixing a bug in S and T path normalization, it seems to work now. I updated *the Random Path Generator* so that it generates only arcs, so it's easy test all possible path combinations:
http://jsbin.com/oqojan/53/
Test and if some path fails, I'd be happy to get report.
EDIT: Just realized that this is 3 years old thread...
There's Mathematica code at Wolfram MathWorld: Bézier Curve Approximation of an Arc, which should get you started.
See also:
I stumbled upon this problem recently. I compiled a solution from the articles mentioned here in the form of a module.
It accepts start angle, end angle, center and radius as input.
It approximates small arcs (<= PI/2) pretty well. If you need to approximate something arcs from PI/2 to 2*PI you can always break them in parts < PI/2, calculate the according curves and join them afterward.
This solution is start and end angle order agnostic - it always picks the minor arc.
As a result you get all four points you need to define a cubic bezier curve in absolute coordinates.
I think this is best explained in code and comments:
A nice explanation is provided in "Approximation of a "Cubic Bezier Curve by Circular Arcs"
Long story short: using Bezier curves you can achieve a minimum error of 1.96×10^-4, which is pretty ok for most applications.
For a positive quadrant arc, use the following points:
where K is a so-called "magic number", which is an non-rational number. It can be approximated as follows:
This isn't easily explained in a StackOverflow post, particularly since proving it to you will involve a number of detailed steps. However, what you're describing is a common question and there's a number of thorough explanations. See here and here; I like #2 very much and have used it before.
This is an 8-year-old question, but one that I recently struggled with, so I thought I'd share what I came up with. I spent a lot of time trying to use solution (9) from this text and couldn't get any sensible numbers out of it until I did some Googling and learned that, apparently, there were some typos in the equations. Per the corrections listed in this blog post, given the start and end points of the arc ([x1, y1] and [x4, y4], respectively) and the the center of the circle ([xc, yc]), one can derive the control points for a cubic bezier curve ([x2, y2] and [x3, y3]) as follows:
Hope this helps someone other than me!