# Drawing a circle tangent to a given circle and its origin is on y-axis

I am facing a problem and I do not know if it is solvable or not.

Suppose I have 2 points and a distance, $P_1$, $P_2$ and $D_x$ respectively.

I need a mathematical way to find the center of a circle $\mathcal{C}_1$ that satisfies the following:

1. The center of $\mathcal{C}_1$ is on the y-axis
2. $P_1$ is on the circumference $\mathcal{C}_1$
3. $\mathcal{C}_1$ is tangent to circle $\mathcal{C}_2$, where $\mathcal{C}_2$'s center is $P_2$ and its radius is $D_x$.

I tried a lot to find it but I could not.

-

If $\mathcal C_1$ with radius $r$ is tangent to $\mathcal C_2$, then $\mathcal C_1$ is at distance $|r\pm D_x|$ from $P_2$. Thus we can rephrase the problem as finding a point on the $y$ axis at distance $r$ from $P_1$ and $|r\pm D_x|$ from $P_2$. Let $(x_1,y_1)$, $(x_2,y_2)$ and $(0,y)$ denote the coordinates of $P_1$, $P_2$ and the centre of $\mathcal C_1$, respectively. Then

\begin{align} x_1^2+(y-y_1)^2&=r^2\;,\\ x_2^2+(y-y_2)^2&=(r\pm D_x)^2\;. \end{align}

Subtracting the two equations yields a linear relationship between $y$ and $r$:

$$x_2^2+y_2^2-(x_1^2+y_1^2)+2y(y_1-y_2)=D_x^2\pm2D_xr\;.$$

For given $y$, exactly one of the solutions for $r$ is non-negative. Solving for $r$ and substituting into the first equation yields

$$4D_x^2\left(x_1^2+(y-y_1)^2\right)=\left(x_2^2+y_2^2-(x_1^2+y_1^2)+2y(y_1-y_2)-D_x^2\right)^2\;.$$

According to Wolfram|Alpha, the discriminant of this quadratic equation in $y$ has three roots with respect to $D_x^2$. The one at $D_x^2=0$ is clear: If the circle degenerates to a point, the two solutions coalesce. The other two roots have a nice interpretation. Here $D_x$ is the distance from $P_2$ to $P_1$ and to the reflection of $P_1$ in the $y$ axis, respectively. Any circle with centre on the $y$ axis that goes through $P_1$ also goes through the reflection of $P_1$ in the $y$ axis. If one of these two points is inside $\mathcal C_2$ and the other is outside, a circle through both of them necessarily intersects $\mathcal C_2$, so in this case the problem has no solution. There are two solutions if $P_1$ and its reflection in the $y$ axis either both lie inside or both lie outside $\mathcal C_2$. If one of them lies exactly on $\mathcal C_2$, there is one solution, with the point of tangency coinciding with the point that lies on $\mathcal C_2$, and the centre of $\mathcal C_1$ given by the intersection of the $y$ axis with the line containing the radius of $\mathcal C_2$ through that point.

-
Thank you! You made my day. – mohamed ehab Sep 20 '12 at 10:22
@mohamed: You're welcome! – joriki Sep 20 '12 at 10:24
but I do not understand something, In wolfram's link, $\mathcal k$ is considered the variable, not $\mathcal y$.... right ? If this is true, I already know $\mathcal k$ (which is $\mathcal D_x$ in my case), but I do not know $\mathcal y$. – mohamed ehab Sep 20 '12 at 10:48
@mohamed: I think that's a misunderstanding. The discriminant is the discriminant with respect to $y$ (indicated by the "$\{y\}$" at the end of the "Input" field), and then the roots of that discriminant with respect to $k$ are given. These are the values of $k$ at which the quadratic equation in $y$ switches from two solutions through one solution to zero solutions. That is, if you fix $P_1$ and $P_2$ and let $k$ vary, there are two solutions for $y$ either if $k$ is small enough that both $P_1$ and its reflection are outside $\mathcal C_2$, or if $k$ is large enough that they're both inside. – joriki Sep 20 '12 at 11:04