2
\$\begingroup\$

I was looking at the descriptions of various curve techniques here and noticed the mention of circular arcs. I want to implement something like this, but I'm not quite sure what the correct formula to use is. I can easily find formulas for Bezier or Hermite curves, but when I search for circular arc splines or circular arc interpolation I get a lot of ultra technical articles that are far beyond what I need. My hunch is that I take the angle formed between the endpoints and the control point and use that radius, but I'm still a little too wobbly conceptually to be able to guess a formula.

For those who cannot follow the link, the circle data is given by a starting point and end point which lie on the circle as well as a control point which is used to control the angle.

What formula can I use to interpolate over and approximate an arc of a circle given these three points?

\$\endgroup\$
  • \$\begingroup\$ It appears that the "control point" for the arcs in the linked article is at the intersection of the tangents at the endpoints (same as a quadratic bezier curve), but you're correct that the point you really need is the center of the circle containing the arc. This point will be at the intersection of the lines perpendicular to the tangent directions at the endpoints. \$\endgroup\$ – bcrist May 19 '14 at 6:29
  • \$\begingroup\$ You can draw a circle through any three non-collinear points. However, if the middle point is not on the circle, but the intersection point of the tangents as bcrist describes, then there may not always be a circle that touches both points with the desired tangents (there is, however, a satisfying ellipse). This is why the example at the link constrains this middle point to be equidistant from the two endpoints. So: do you want a circle joining three arbitrary points, an ellipse through two points with a free control point, or a circle through two points with a constrained control point? \$\endgroup\$ – DMGregory May 20 '14 at 18:32
  • \$\begingroup\$ @DMGregory the impression I got from the site I linked was that as long as the control point is constrained such that it intersects both the midpoint of the line connecting the other two points and the center of the circle then there will always be a circle. That's what I'm looking for. \$\endgroup\$ – ssb May 20 '14 at 23:10
5
\$\begingroup\$

Let's assume you want a circular arc from point A to point B, guided by control handle H which is the intersection of the tangents at A & B (and thus equidistant from A & B).

enter image description here

Circles being the bread & butter of geometry, there are a hundred ways to skin this cat - but here's one...

If we define:

midpoint = (A + B)/2;
perpendicular = (-(B - midpoint).y, (B - midpoint).x);

then this can equivalently be expressed with two points A & B and a ratio h, such that

H = midpoint + h * perpendicular;

where values of h > 0 correspond to arcs turning to the right/clockwise from A to B, and < 0 are arcs turning left/counterclockwise (assuming x+ points right and y+ points up - sometimes y is inverted). h = 0 is the degenerate case of a straight line - use linear interpolation if h is very close to zero, as the method is numerically unstable when the radius approaches infinity.

We can use this to compute a center point, radius, start angle, and angular delta between the points:

center = midpoint - perpendicular/h;

radius = Length(A - center);

startAngle = atan2(A - center);

endAngle = atan2(B - center);

angleDelta = endAngle - startAngle;
if(angleDelta * h > 0)
{
   angleDelta -= sign(h) * 2 * PI;
}

Then your formula for a point with interpolation weight t in [0, 1] along the arc is:

angle = startAngle + angleDelta * t;
point = center + radius * (cos(angle), sin(angle));

And the length of the arc is simply r * abs(angleDelta)

\$\endgroup\$
  • \$\begingroup\$ Sorry, there was a calculation error in my original - I've corrected it above. You don't need to divide by the square of the perpendicular's length. \$\endgroup\$ – DMGregory May 21 '14 at 4:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.