Sooooo many ways to do this. Here are two.
#1. Just basic algebra. You have two circles.
(x-x1)^2 + (y-y1)^2 = r^2
(x-x2)^2 + (y-y2)^2 = r^2
You are looking for the pair of lines that cross, so are tangent to opposite sides of the circle.
Where is the intersection of those lines? An easy conclusion, since the circles have the same radii, is that the intersection point MUST lie at the mid-point between the two circle centers. Thus:
x0 = (x1 + x2)/2
y0 = (y1 + y2)/2
The lines MUST EACH pass through that point, (x0,y0). Those lines can then be written as
y - y0 = s*(x-x0)
y - y0 = t*(x-x0)
where s and t are the respective slopes of the pair of lines.
Now, just find the intersection of one of those lines with the circles. Do so by substituting for y in the circle equation:
subs((x-x1)^2 + (y-y1)^2 - r^2,y,y0+s*(x-x0))
ans =
(x - x1)^2 + (y1/2 - y2/2 + s*(x1/2 - x + x2/2))^2 - r^2
Solve for x, such that we have an intersection. Of course, we get two solutions.
solve((x - x1)^2 + (y1/2 - y2/2 + s*(x1/2 - x + x2/2))^2 - r^2,x)
ans =
(2*x1 + s*y1 - s*y2 + s^2*x1 + s^2*x2 + (4*r^2*s^2 + 4*r^2 - s^2*x1^2 + 2*s^2*x1*x2 - s^2*x2^2 + 2*s*x1*y1 - 2*s*x1*y2 - 2*s*x2*y1 + 2*s*x2*y2 - y1^2 + 2*y1*y2 - y2^2)^(½))/(2*(s^2 + 1))
(2*x1 + s*y1 - s*y2 + s^2*x1 + s^2*x2 - (4*r^2*s^2 + 4*r^2 - s^2*x1^2 + 2*s^2*x1*x2 - s^2*x2^2 + 2*s*x1*y1 - 2*s*x1*y2 - 2*s*x2*y1 + 2*s*x2*y2 - y1^2 + 2*y1*y2 - y2^2)^(½))/(2*(s^2 + 1))
But that was a quadratic polyomial, and we know that we wish a single solution for the intersection. So solve for the slope that yields a discriminant of zero in that solution.
s = solve(4*r^2*s^2 + 4*r^2 - s^2*x1^2 + 2*s^2*x1*x2 - s^2*x2^2 + 2*s*x1*y1 - 2*s*x1*y2 - 2*s*x2*y1 + 2*s*x2*y2 - y1^2 + 2*y1*y2 - y2^2==0,s)
s =
(x1*y2 - x1*y1 + x2*y1 - x2*y2 + 2*r*(- 4*r^2 + x1^2 - 2*x1*x2 + x2^2 + y1^2 - 2*y1*y2 + y2^2)^(1/2))/(4*r^2 - x1^2 + 2*x1*x2 - x2^2)
-(x1*y1 - x1*y2 - x2*y1 + x2*y2 + 2*r*(- 4*r^2 + x1^2 - 2*x1*x2 + x2^2 + y1^2 - 2*y1*y2 + y2^2)^(1/2))/(4*r^2 - x1^2 + 2*x1*x2 - x2^2)
So we have found the two possible slopes. We could go ahead and compute the intersection points, etc.
=======================================
#2. Basic geometry.
Given circles, centered at [x1,y1] and [x2,y2], each of radius r. Find the tangent points.
Answer: USE RIGHT TRIANGLES!
As we stated before, the intersection point of the lines happens at
[x0,y0] = [(x1 + x2)/2, (y1 + y2)/2]
The distance between the circle centers is
D = norm([x1,y1] - [x2,y2])
So the distance from the center of either circle to the mid-point is D/2.
The radius of each circle is r. And the line tangent to a circle MUST make a right triangle where it touches that circle as a tangent. The right triangle has hypotenuse of length D/2, one side of length r, and therefore the third side, by virtue of the pythagorean theorem has length...
The angles of that triangle are now trivially found from a little trigonometry. How did it go? SOHCAHTOA. Easy, peasy.
Use method 2. It is a lot less messy.
Best Answer