Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Given an arbitrary arc, where you know the following values: start point (x0,y0), end point (x1,y1), radius (r) and arc direction (e.g. clockwise or counterclockwise from start to end), how can I calculate the arc's center? i know from this previous post (thanks!) that the center lies on the perpendicular bisector between the two points, but don't know how to calculate it.

thanks!

share|improve this question
1  
I am interested in this answer for a cnc machine emulation I am programming. The answer I desire is solved generically for x or y (the other would be trivial given one of them) for both possible points. I have tried to solve this myself, but am getting pretty lost. I tried to solve by (x-a)^2 + (y-b)^2 = (x-c)^2 + (y-d)^2 than plug back in to first equation. –  Joe McGrath Dec 1 '11 at 6:21
    
Is this arc suppose to be a segment of circle? other wise talking about arc's center is of a non-circualar segment's center, –  Arjang Dec 1 '11 at 7:02
add comment

12 Answers

up vote 3 down vote accepted

To be explicit, your equations are $r^2=(x-x_0)^2+(y-y_0)^2$ and $r^2=(x-x_1)^2+(y-y_1)^2$ Subtracting them gives the bisector line: $0=2x(x_1-x_0)+x_0^2-x_1^2+2y(y_1-y_0)+y_0^2-y_1^2$. You can solve any two of these simultaneously to get the two candidate centers.

share|improve this answer
    
hey ross, so how do i rearrange one of these equations to first solve for x, than for y, when they contain both x and y as unknowns? i figure i can rearrange the first one to solve for x like this: x = -x0^2 + (y-y0)^2 = r^2. but that still has the unknown y on the right side. –  mix Mar 17 '11 at 19:25
1  
That is not right, because $(x-x_0)^2\neq x^2-x_0^2$. The bisector one, being linear, is a good place to start: you can get $x=\frac{-2y(y_1-y_0)+x_1^2+y_1^2-y_0^2-x_0^2}{x_1-x_0}$. Now substitute that for $x$ into one of the other equations and you will get a quadratic for $y$. When you solve that, you will get two values for $y$, which you can substitute back into the first linear equation to get $x$ –  Ross Millikan Mar 17 '11 at 19:50
    
if i substitute that equation for x, i still end up with an unknown (y), right? IOW, even though i can rearrange the original equations to solve for y, what you're suggesting still leaves a y on the right side. or am i missing something? –  mix Mar 18 '11 at 21:18
    
When you have two simultaneous equations in two unknowns, you solve one equation for one in terms of the other. Then you can substitute that into the other, leaving one equation in one variable. When you have solved that, put that value in to find the first variable. A discussion is at purplemath.com/modules/systlin4.htm –  Ross Millikan Mar 18 '11 at 21:50
add comment

Let $(x,y)$ be the center of the arc. For $i=1,2$ write the equation $$ \text{distance from $(x,y)$ to $(x_i,y_i)$}=r. $$ You get a system of two quadratic equations in the two unknowns $x$ and $y$. Solve it to find two solutions, each on a different side of the segment from $(x_1,y_1)$ to $(x_2,y_2)$. Choose the one that corresponds to the direction of the arc.

share|improve this answer
1  
System of two quadratic equations is a pain to solve from the scratch. There are better ways... –  valdo Dec 1 '11 at 10:51
add comment

Let's try a geometric approach:

We are given the points $A$ and $B$ on the circle and the radius $r$ of the circle.

I'll do it for a specific case:

Suppose $A$ and $B$ are in the first quadrant with $A$ "to the left and above" $B$.

Let $D$ be the midpoint of the line segment $\overline{AB}$ and set $\gamma$ equal to the acute angle formed by $\overline{AB}$ and the horizontal line $l$ through $A$.

Let $V=\overline{DC}$ where $C$ is the center of the circle.

Then:

1) The length of $V$ is $\sqrt{r^2-{{|\overline{AB}|^2\over 4 }}}$.

2) The acute angle formed by the horizontal line through $D$ and $\overline{DC}$ is ${\pi\over 2}-\gamma$.

Since you can compute the coordinates of $D$ and $\gamma$ from the coordinates of $A$ and $B$, you can find the coordinates of $C$ using the information in 1) and 2).

share|improve this answer
add comment

Don't write down too many equations to be solved, but produce the desired center ${\bf c}=(a,b)$ in a forward movement instead. Let ${\bf z}_i=(x_i,y_i)$ $\ (i=0,1)$ be the two given points, put $\epsilon:=1$ if the arc should go from ${\bf z}_0$ to ${\bf z}_1$ counterclockwise, and put $\epsilon:=-1$ otherwise.

Next, let $d:=|{\bf z_1}-{\bf z_0}|=\sqrt{(x_1-x_0)^2+(y_1-y_0)^2}$ be the distance and ${\bf m}:=\bigl({x_0+x_1 \over2}, {y_0+y_1\over2}\bigr)$ be the midpoint of ${\bf z_0}$ and ${\bf z_1}$. Then

$${\bf n}:=(u,v):=\Bigl({x_1-x_0\over d},{y_1-y_0\over d}\Bigr)$$

is the unit normal in the direction ${\bf z_1}-{\bf z}_0$, and ${\bf n}^*:=(-v,u)$ is the unit vector you get by rotating ${\bf n}$ counterclockwise by $90^\circ$.

Given $r>0$ the center ${\bf c}$ has a distance $h:=\sqrt{r^2 -d^2/4}$ from ${\bf m}$, and the given $\epsilon$ together with ${\bf n}^*$ tell us in which direction we should go. In vectorial notation the center is given by

$${\bf c}\ =\ {\bf m}+\epsilon\ h\ {\bf n}^*\ ,$$

so that coordinate-wise we get

$$a={x_0+x_1 \over2}-\epsilon\ h\ v, \qquad b={y_0+y_1 \over2}+\epsilon\ h\ u\ .$$

share|improve this answer
add comment

So I gave up with my pen and paper and just put it into my TI-89

a = pointA x
b = pointA y
c = pointB x
d = pointB y

Start with:

$(x-a)^2+(y-b)^2-(x-c)^2-(y-d)^2=0$

Solve for Y

$y=\frac{-(2(a-c)x-a^s-b^2+c^2+d^2)}{2(b-d)}$

Solve for X in $(x-a)^2+(y-b)^2=r^2$

$x= \frac {- \left( |b-d|\sqrt{4r^2-a^2+2ac-b^2+2bd-c^2-d^2}-(a+c)\sqrt{a^2-2ac+b^2-2bd+c^2+d^2} \right) } { 2 \sqrt{a^2-2ac+b^2-2bd+c^2+d^2}} $

or

$x= \frac { |b-d|\sqrt{4r^2-a^2+2ac-b^2+2bd-c^2-d^2}+(a+c)\sqrt{a^2-2ac+b^2-2bd+c^2+d^2} } { 2 \sqrt{a^2-2ac+b^2-2bd+c^2+d^2}} $

share|improve this answer
add comment

Even the direction of the arc is defined(clockwise or counter-clockwise), there are generally two possible solutions, because the radius angle could be less or greater than $\pi$. Let me show you by the planar vector method:

Given the start point $A(x_0,y_0)$and end point $B(x_1,y_1)$,let $|\vec{AB}|=2l$, so $l=\frac{\sqrt{(x_1-x_0)^2+(y_1-y_0)^2}}{2}$. Let the midpoint of $AB$ is point $M$, we know the center point $O$ is subject to $OM\perp AB$, and $|\vec{AM}|=l,|\vec{MO}|=\sqrt{r^2-l^2}$.

Now, $\vec{AM}=(\frac{x_1-x_0}{2}+i(\frac{y_1-y_0}{2}))$, since $OM\perp AB$, we get $\vec{MO}=\frac{|\vec{MO}|}{|\vec{AM}|}\cdot\vec{AM}\times (cos\theta+i\cdot sin\theta)$, where $\theta=\frac{\pi}{2}$ or $\theta=-\frac{\pi}{2}$, depending on the rotary direction of the arc and whether the radius angle is less than $\pi$.

Case 1: $\theta=\frac{\pi}{2}$. we get $\vec{MO}=\frac{\sqrt{r^2-l^2}}{l}\cdot[(-\frac{y_1-y_0}{2})+i(\frac{x_1-x_0}{2})]$. Since $\vec{MO}=(x-\frac{x_0+x_1}{2})+i(y-\frac{y_0+y_1}{2})$, comparing the real and imaginary part, we konw $x=\frac{x_0+x_1}{2}-\frac{(y_1-y_0)\sqrt{r^2-l^2}}{2l}$ and $y=\frac{y_0+y_1}{2}+\frac{(x_1-x_0)\sqrt{r^2-l^2}}{2l}$.

Case 2: $\theta=-\frac{\pi}{2}$.we get $\vec{MO}=\frac{\sqrt{r^2-l^2}}{l}\cdot[(\frac{y_1-y_0}{2})-i(\frac{x_1-x_0}{2})]$. Comparing again, we know $x=\frac{x_0+x_1}{2}+\frac{(y_1-y_0)\sqrt{r^2-l^2}}{2l}$ and $y=\frac{y_0+y_1}{2}-\frac{(x_1-x_0)\sqrt{r^2-l^2}}{2l}$.

When shold $\theta$ be $\frac{\pi}{2}$ or $-\frac{\pi}{2}$?

By drawing a circle and observing the different cases, it's easy to know: $counter-clockwise\ and\ radius\ angle\ is \gt\pi: \theta=-\frac{\pi}{2}$.

$counter-clockwise\ and\ radius\ angle\ is \lt\pi: \theta=\frac{\pi}{2}$.

$clockwise\ and\ radius\ angle\ is \gt\pi: \theta=\frac{\pi}{2}$.

$clockwise\ and\ radius\ angle\ is \lt\pi: \theta=-\frac{\pi}{2}$.

Also, you can see there is no solution when $l\lt r$ and there is only one solution when $l=r$.

share|improve this answer
add comment

Consider the two circles with centers $(x_0,y_0)$ and $(x_1,y_1)$ and radius $r$. With some luck they will intersect (if they don't, there is no solution), probably in two points. If there are two points of intersection and if you want your arc to be shorter than a semicircle, choose the center of you arc to be the point of intersection on the same side as your arc should turn (left or right) w.r.t. the line from $(x_0,y_0)$ to $(x_1,y_1)$. If you prefer an arc longer than a semicircle, choose the other point of intersection. In case there is only one point of intersection, that's you center; choose the semicircle that turn in the proper direction.

share|improve this answer
add comment

This is to long for a comment so I put as a answer.

We can find the length of a arc using this, so to your problem we have:

$r^2=(x-x_c)^2+(y-y_c)^2$

Isolating $y$

$y=y_c-\sqrt{-x_c^2+2 x x_c+r^2-x^2}$

or

$y=y_c+\sqrt{-x_c^2+2 x x_c+r^2-x^2}$

And

$y'= -\frac{2 x_c-2 x}{2 \sqrt{2 x x_c-x_c^2-x^2+r^2}} $

or

$y'= \frac{2 x_c-2 x}{2 \sqrt{2 x x_c-x_c^2-x^2+r^2}} $

So the distance of $x=x_a$ to $x=x_b$, using the formula and the Elliptic Integral (Wolfram) is:

$$ d_{x_a,x_b}=r (E\left(\left.\arcsin\left(\frac{x_b-x_c}{r}\right)\right|2\right)-E\left(\left.\arcsin\left(\frac{x_a-x_c}{r}\right)\right|2\right)) $$

or

$$ d_{x_a,x_b}=r (E\left(\left.\arcsin\left(\frac{x_b-x_c}{r}\right)\right|2\right)-E\left(\left.\arcsin\left(\frac{x_a-x_c}{r}\right)\right|2\right)) $$

But, do you want to know a distance of a point m $(x_m,y_m)$ when

$d_{x_0,x_1}=2d_{x_0,x_m}$.

Maybe it helps.

share|improve this answer
add comment

Here is an equivalent algebraic solution. Let's first assume that $x_1=y_1=0$ (this will be generalized later). We're looking for a point $(x,y)$ which is at distance $r$ of $(x_0,y_0)$ and $(x_1,y_1)$, thus

$$ x^2 + y^2 = r^2$$ and $$ (x-x_0)^2 + (y-y_0)^2 = r^2$$

We get from that

$$x^2+y^2 = (x-x_0)^2 + (y-y_0)^2$$

which simplifies to

$$ s = xx_0 + yy_0$$

if we call $$s = \frac{x_0^2 + y_0^2}{2}$$

Now let's multiply each side of the first equation by $y_0^2$ and substitute $ s = xx_0 + yy_0$. We get

$$ x^2y_0^2 + (s - xx_0)^2 = r^2y_0^2 $$

This can be solved with the quadratic formula, giving, after some simplifications,

$$ x = \frac{x_0}{2} \pm \frac{y_0}{2}\sqrt{ 2\frac{r^2}{s} -1 } $$

If we generalize to any $(x_1,y_1)$ by translating the problem, this becomes

$$ x = \frac{x_0 + x_1}{2} \pm \frac{y_0-y_1}{2}\sqrt{ \left( \frac{2r}{d} \right)^2 - 1} $$

where $d$ is now the distance between $(x_0,y_0)$ and $(x_1,y_1)$, $\sqrt{(x_0-x_1)^2 + (y_0-y_1)^2}$.

Similarly, we can get

$$ y = \frac{y_0 + y_1}{2} \mp \frac{x_0-x_1}{2}\sqrt{ \left( \frac{2r}{d} \right)^2 - 1} $$

And of course the $\pm$ can be deduced from the direction of the arc.

This should be equivalent to the vectorial version already mentioned.

share|improve this answer
add comment

This is called the endpoint parameterization of an ellipse. The SVG image format uses it to specify elliptical arcs, and the W3C specification contains the formulas for converting to the standard center parameterization.

http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes

It also contains some suggestions for handling some common error conditions, such as when the radii are too small to span the points.

share|improve this answer
add comment

I'am using something like this (c#):

        public PointF ArcCenter(PointF P1, PointF P2, Double Radius, int Direction,ref string ErrorDescription)
        {
            // returns arc center based on start and end points, radius and arc direction (2=CW, 3=CCW)
            // Radius can be negative (for arcs over 180 degrees)
            double Angle = 0, AdditionalAngle = 0, L1 = 0, L2 = 0, Diff=0;
            double AllowedError = 0.002;
            PointF Center = new PointF(0, 0);
            ErrorDescription = "";
            PointF T1, T2;

            // Sort points depending of direction
            if (Direction == 2)
            {
                T1 = new PointF(P2.X, P2.Y);
                T2 = new PointF(P1.X, P1.Y);
            }
            else // 03
            {
                T1 = new PointF(P1.X, P1.Y);
                T2 = new PointF(P2.X, P2.Y);
            }

            // find angle arc covers
            Angle = CalculateAngle(T1, T2);

            L1 = PointDistance(T1, T2) / 2;
            Diff = L1 - Math.Abs(Radius);

            if (Math.Abs(Radius) < L1 && Diff > AllowedError)
            {
                ErrorDescription = "Error - wrong radius";
                return Center;
            }

            L2 = Math.Sqrt(Math.Abs(Math.Pow(Radius,2) - Math.Pow(L1,2)));

            if (L1 == 0)
                AdditionalAngle = Math.PI / 2;
            else
                AdditionalAngle = Math.Atan(L2 / L1);

            // Add or subtract from angle (depending of radius sign)
            if (Radius < 0)
                Angle -= AdditionalAngle;
            else
                Angle += AdditionalAngle;

            // calculate center (from T1)
            Center = new PointF((float) (T1.X + Math.Abs(Radius) * Math.Cos(Angle)), (float) (T1.Y + Math.Abs(Radius) * Math.Sin(Angle)));
            return Center;
        }

        public double CalculateAngle(PointF P1, PointF P2)
        {
            // returns Angle of line between 2 points and X axis (according to quadrants)
            double Angle = 0;

            if (P1 == P2) // same points
                return 0;
            else if (P1.X == P2.X) // 90 or 270
            {
                Angle = Math.PI / 2;
                if (P1.Y > P2.Y) Angle += Math.PI;
            }
            else if (P1.Y == P2.Y) // 0 or 180
            {
                Angle = 0;
                if (P1.X > P2.X) Angle += Math.PI;
            }
            else
            {
                Angle = Math.Atan(Math.Abs((P2.Y - P1.Y) / (P2.X - P1.X))); // 1. quadrant
                if (P1.X > P2.X && P1.Y < P2.Y) // 2. quadrant
                    Angle = Math.PI - Angle;
                else if (P1.X > P2.X && P1.Y > P2.Y) // 3. quadrant
                    Angle += Math.PI;
                else if (P1.X < P2.X && P1.Y > P2.Y) // 4. quadrant
                    Angle = 2 * Math.PI - Angle;
            }
            return Angle;
        }

        public double PointDistance(PointF P1, PointF P2)
        {
            return Math.Sqrt(Math.Pow((P2.X - P1.X), 2) + Math.Pow((P2.Y - P1.Y), 2));
        }
share|improve this answer
add comment

One possible way could be an arc midpoint computation shown at http://mathcentral.uregina.ca/RR/database/RR.09.10/akulov2.html

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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