views:

85

answers:

2

How could I implement in C a simple way to generate the 2 missing control points for an elliptic arc given a start and end point? I don't need fancy error estimation, just something that can take points A and D and generate the control points B and C for the elliptical arc where I can then use the cubic bezier interpolation algorithm to generate the curve.

something like

void GetArcControlPoints(Point a, Point &b, Point &c, Point d)
{

.....
b = ...
c = ....
}

Thanks

+3  A: 

There are some flaws in the math behind your question:

  1. Bézier curves are polynomial functions of a parameter t in the unit interval [0;1]. Ellipses are defined using the trigonometrical functions, which are transcendental, thus, not algebraic, thus, not polynomial. You cannot generate an ellipse arc using Bézier curves (neither cubic nor of any degree n). But let's suppose you just want to approximate an ellipse arc. Since you have not specified how good the approximation has to be, there is no way to ensure the Bézier curve will be "ellipse enough" for you. In fewer terms: You need an error parameter.

  2. There are infinite ellipse arcs passing through two given points. Thus, the two points give not enough information to specify an ellipse, an arc of which which could then be approximated using a Bézier curve. To make things worse, since you want an ellipse arc, not the whole ellipse, you also have to specify how much of the ellipse has to be "covered" by the arc, in percentage (100% = the whole ellipse), radians (2*pi = the whole ellipse), whatever. In fewer terms: You need even more (input) parameters, just to specify a single arc of a single ellipse.

Until the math is done right, you cannot go to the next step (coding).


EDIT:

  1. Since you need a whole ellipse, I would recommend using two or four Bézier patches instead of a single Bézier curve.

  2. You can think of the ellipse as a circle that was "stretched" on one of the dimensions. Now, since "stretch" transforms are linear and Bézier functions are linear on the control points, you can calculate the control points for a Bézier curve approximating a 90 degree circle arc, then apply the "stretch" transform to the control points, and voilà, you get the control points for a Bézier curve approximating a "90 degree" ellipse arc. Getting the whole ellipse is just repeating the procedure four times.

Eduardo León
well actually I am drawing a whole ellipse but I thought this would be easier to explain.
Milo
+1  A: 

Here is a derivation for the control points of a unit circle segment:

http://www.whizkidtech.redprince.net/bezier/circle/kappa/

Every possible ellipse can be generated by applying the appropriate affine transformation.

Philipp