Given an arbitrary arc, where you know the following values: start point $(x_0, y_0)$, end point $(x_1, y_1)$, 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.

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 McGrathDec 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,
–
ArjangDec 1 '11 at 7:02

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.
–
mixMar 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 MillikanMar 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?
–
mixMar 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 MillikanMar 18 '11 at 21:50

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

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.

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}$.

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

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.

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.