Given two circles C1(x1,y1,r1) and C2(x2,y2,r2) that either touch externally or do not intersect, and a path (P0-P1-P2-P3) where:
P1 is on C1's circumference
P2 is on C2's circumference
C1 is positioned to maximally overlap angle P0P1P2
C2 is positioned to maximally overlap angle P1P2P3
Find the coordinates of one point where the common external tangent line P10P20 touches either circle,
where P10 is on C1 after P1 (following the path direction) and P20 is on C2 before P2.
Provide a simple, flexible algorithm or equation, with proof, and Javascript implementation.
The solution should handle all cases, including when radii are equal and when circles touch.
Assistant
To find the coordinates of the point where the common external tangent touches either circle, we can use the following algorithm:
Find the distance between the centers of the two circles.
If the distance between the centers of the two circles is less than or equal to the sum of their radii, the circles intersect or touch internally. In this case, we cannot find a common external tangent line.
If the distance between the centers of the two circles is greater than the sum of their radii, the circles do not intersect and we can find a common external tangent line.
Find the slope of the line connecting the centers of the two circles.
Find the slope of the line perpendicular to the line connecting the centers of the two circles.
Find the point of intersection between the line connecting the centers of the two circles and the line perpendicular to it that passes through the point on C1 where the tangent line touches it.
Find the equation of the line connecting the center of C1 and the point of intersection found in step 6.
Find the equation of the line perpendicular to the line connecting the centers of the two circles that passes through the point on C2 where the tangent line touches it.
Find the point of intersection between the lines found in steps 7 and 8.
The point of intersection found in step 9 is the point where the common external tangent line touches either circle.
This function takes the coordinates and radii of the two circles as input and returns the coordinates of the point where the common external tangent line touches either circle. If the circles intersect or touch internally, the function returns null.
The function first checks if the distance between the centers of the two circles is less than or equal to the sum of their radii. If it is, the function returns null because there is no common external tangent line.
If the circles do not intersect, the function finds the slope of the line connecting the centers of the two circles and the slope of the line perpendicular to it. It then finds the point of intersection between the line connecting the centers of the two circles and the line perpendicular to it that passes through the point on C1 where the tangent line touches it. The function then finds the equations of the lines connecting the center of C1 and the point of intersection found in the previous step, and the line perpendicular to the line connecting the centers of the two circles that passes through the point on C2 where the tangent line touches it. Finally, the function finds the point of intersection between the two lines and returns its coordinates.