3
$\begingroup$

Given two lines, each defined by two points, and a radius find the four circles that have the lines as tangents. I give my attempt below but there ought to be a nice mathematica way of doing this.

ClearAll[tangetsAndCircles];
tangetsAndCircles[{p1_, p2_}, {p3_, p4_}, r_] := 
 Module[{L1, L2, intersection, λ1, λ2, s1, 
   s2, θ1, θ2, d1, d2, q1, q2, q3, q4},
  L1 = p1 + λ1 (p2 - p1);
  L2 = p3 + λ2 (p4 - p3);
  intersection = 
   L1 /. First@NSolve[L1 == L2, {λ1, λ2}];
  s1 = Normalize[p2 - intersection] ;
  s2 = Normalize[p4 - intersection ];
  θ1 = 1/2 ArcCos[s1.s2];
  d1 = r/Sin[θ1];
  θ2 = 1/2 ArcCos[-s1.s2];
  d2 = r/Sin[θ2];
  q1 = intersection + d1 (s1 + s2)/Norm[s1 + s2];
  q2 = intersection - d1 (s1 + s2)/Norm[s1 + s2];
  q3 = intersection + d2 (-s1 + s2)/Norm[-s1 + s2];
  q4 = intersection - d2 (-s1 + s2)/Norm[-s1 + s2];
  {intersection, q1, q2, q3, q4}

  ]

Here is an example

{p1, p2, p3, p4} = 
{{0.1246, 0.1491}, {0.0501, -0.8392}, 
 {0.6457, 0.7347}, {-0.4134, -0.2812}};
r = 0.2;

{p, q1, q2, q3, q4} = tangetsAndCircles[{p1, p2}, {p3, p4}, r];

Graphics[{PointSize[0.02], Purple, Point[{p1, p2, p3, p4}], Black, 
  InfiniteLine[{p1, p2}], InfiniteLine[{p3, p4}], Red, Point[p],
  Lighter@Blue, Circle[q1, r], Circle[q2, r], Circle[q3, r], 
  Circle[q4, r]}, Frame -> True]

Mathematica graphics

Can you suggest a simpler and more robust method? Thanks

$\endgroup$
3
$\begingroup$
p = First[RegionIntersection[InfiniteLine[{p1, p2}], InfiniteLine[{p3, p4}]]]
dir1 = r Normalize[Normalize[p4 - p3] + Normalize[p2 - p1]];
dir2 = Cross[dir1];
q1 = p + Csc[VectorAngle[p4 - p3, p2 - p1]/2] dir1;
q2 = p - Csc[VectorAngle[p4 - p3, p2 - p1]/2] dir1;
q3 = p + Csc[VectorAngle[p4 - p3, p1 - p2]/2] dir2;
q4 = p - Csc[VectorAngle[p4 - p3, p1 - p2]/2] dir2;

The use of Csc is like computing the green length below where the orange and blue segments correspond to your lines:

$\endgroup$
  • $\begingroup$ Thanks, nice use of RegionIntersection . VectorAngle is also one to get to know. $\endgroup$ – Hugh Nov 6 '18 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.