Finding circle with two points on it and a tangent from one of the points

Two points P1(x1,y1) and P2(x2,y2) are known. In addition, a line slope passing through P1 is known. The aim is to construct a circle (or circular arc) that it passes through both P1 and P2 and it is tangent to the line. How can we find the center of the circle and the radius with those given information? (2 points and 1 tangent)

As it can be seen in the figure, the radius and the center (in green) are unknown and aim is to find the center point and radius (or curvature)

• $$(x_1-x_0)^2+(y_1-y_0)^2=r^2\tag{1}$$ $$(x_2-x_0)^2+(y_2-y_0)^2=r^2\tag{2}$$ $$\mathrm{d}(K,p_0)=\frac{|Ax^2+Bx+C|}{\sqrt{A^2+B^2}}=r\tag{3}$$ – UserX Oct 29 '14 at 12:19
• $$-\frac{A}{B}=m\tag{4}$$ $$P(x_1,y_1) \in K \iff Ax_1+Bx_2+C=0\tag{5}$$ These are the information I extracted. – UserX Oct 29 '14 at 12:19
• The center is on the line perpendicular to the tangent, and it's also equidistant from the two points, which puts it on the perpendicular bisector of the line segment joining the two points. – Gerry Myerson Oct 29 '14 at 12:31
• Thank you for the method, I also tried to apply something similar, however the problem is that this calculation is done many times in a simulation and sometimes the slope can be 0, then the slope of the perpendicular line to this slope becomes infinity and I think that creates a problem. Is it possible to find the center and radius (what I need) without using the slope of the virtual line perpendicular to m and passing through P1 and center? – birincilikteli Oct 29 '14 at 13:48

Let the given line be $ax+by=c$. If you just have its slope $m$, you can take $a=-m$ and $b=1$. (And $c=ax_1+by_1$, but we're not going to use that.) A perpendicular line has the form $bx-ay = \text{something}$, and the something can be determined by using the fact that the line is supposed to go through P1. Thus our first line is $$bx - ay = bx_1 - ay_1 \tag{1}$$ The line through P1 and P2 is $$(y_1-y_2)x - (x_1-x_2)y = x_2y_1 - x_1y_2$$ A perpendicular line has the form $$(x_1-x_2)x + (y_1-y_2)y = \text{something}$$ and the something can be determined by the fact that we want the line to go through the midpoint of P1P2, that is, $(\frac12(x_1+x_2),\frac12(y_1+y_2))$. Thus our second line is $$(x_1-x_2)x + (y_1-y_2)y = \tfrac12(x_1^2+y_1^2-x_2^2-y_2^2) \tag{2}$$ The equations (1) and (2) together form a linear system which can be solved by standard methods, e.g., Cramer's rule. The solution is the centre of the desired circle, and the radius, if needed, is the distance from that point to P1.
• Use normal equations $ax+by=c$ instead of point-slope equations $y=mx+b$; they handle vertical lines much better. (Also, you can solve the resulting linear system explicitly via Cramer's rule, which doesn't require any assumptions about particular variables being nonzero.) – user21467 Oct 29 '14 at 14:01