Search code examples
mathgeometrywolfram-mathematicacomputational-geometrysage

Find Tangent Points of Circle and Two Lines in First Quadrant


I need to define explicit expressions to find the points (x1,y1) and (x2,y2), which are the two tangent points of a circle with radius r (known) and two lines (equations known). The center of the circle (x0,y0) is not know and not needed. See picture below.

enter image description here

In my case, I have the following conditions:

  1. problem in first quadrant: x>0, y>0
  2. line y=m1*x+b1 with m1<=0, b1>=0
  3. line y=m2*x+b2 with m2 < m1, b2>b1
  4. circle centre above y=m1*x+b1, so y0>y1
  5. circle centre at r.h.s. of y=m2*x+b2, so x0>x2
  6. circle tangent to line y=m1*x+b1, so (y1-y0)/(x1-x0)=-1/m1
  7. circle tangent to line y=m2*x+b2, so (y2-y0)/(x2-x0)=-1/m2

I computed the following:

x1, y1, x2, y2 = var('x1, y1, x2, y2')   # tangent points
m1, b1, m2, b2 = var('m1, b1, m2, b2')   # lines' eqn
x0, y0, r = var('x0, y0, r')             # cirsle's eqn

eq1 = (x1 - x0)^2 + (y1 - y0)^2 - r^2 == 0
eq2 = (x2 - x0)^2 + (y2 - y0)^2 - r^2 == 0
eq3 = y1 - m1*x1 - b1 == 0
eq4 = y2 - m2*x2 - b2 == 0
eq5 = (y1-y0)/(x1-x0) == -1/m1
eq6 = (y2-y0)/(x2-x0) == -1/m2

# unknown: x0,y0,x1,y1,x2,y2
#   known: m1,b1,m2,b2,r

solve([eq1,eq2,eq3,eq4,eq5,eq6,
       x1>0,y1>0,x2>0,y2>0,
       m1<=0,b1>=0,m2<m1,b2>b1,
       x0>x2,y0>y1,r>0],x0,y0,x1,y1,x2,y2)

Why is this not enough to define the problem?


Solution

  • Computing x1, y1, x2 and y2 as unknowns

    Clear[m1, x1, b1, m2, x2, b2, r, x0]
    y1 = m1 x1 + b1;
    y2 = m2 x2 + b2;
    s1 = r/Sqrt[1 + 1/m1^2];
    s2 = r/Sqrt[1 + 1/m2^2];
    
    x0 = x0 /. FullSimplify@Solve[
         m1 x0 + b1 + (s1 (-(1/m1)) - s1 m1) == 
          m2 x0 + b2 + (s2 (-(1/m2)) - s2 m2), x0][[1]]
    

    (-b1 + b2 + Sqrt[1 + 1/m1^2] m1 r - Sqrt[1 + 1/m2^2] m2 r)/(m1 - m2)

    y0 = FullSimplify[m1 x0 + b1 + (s1 (-(1/m1)) - s1 m1)]
    

    (b2 m1 - m2 (b1 + m1 (-Sqrt[1 + 1/m1^2] + Sqrt[1 + 1/m2^2]) r))/(m1 - m2)

    x1 = x1 /. FullSimplify@
       Solve[{(x1 - x0)^2 + (y1 - y0)^2 == r^2}, x1][[1]]
    

    (r + m1 m2 r - Sqrt[1 + 1/m1^2] m1 (b1 - b2 + Sqrt[1 + 1/m2^2] m2 r))/(Sqrt[ 1 + 1/m1^2] m1 (m1 - m2))

    x2 = x2 /. FullSimplify@
       Solve[{(x2 - x0)^2 + (y2 - y0)^2 == r^2}, x2][[1]]
    

    (b2 - b1 (1 + m2^2) + Sqrt[1 + 1/m1^2] m1 r + m2 (b2 m2 - (Sqrt[1 + 1/m2^2] + m1 (-Sqrt[1 + 1/m1^2] + Sqrt[1 + 1/m2^2]) m2) r))/((m1 - m2) (1 + m2^2))

    Testing with values

    m1 = -0.28; b1 = 1.64; m2 = -1.08; b2 = 3.84;
    r = 3.9062658021579098;
    
    {x1, y1}
    {x2, y2}
    

    {3.81302, 0.572355}

    {2., 1.68}

    Show[Plot[
      {m1 x + b1,
       m1 x + b1 + (s1 (-(1/m1)) - s1 m1),
       m2 x + b2,
       m2 x + b2 + (s2 (-(1/m2)) - s2 m2)}, {x, 0, 10},
      PlotRange -> {{0, 10}, {0, 10}}, AspectRatio -> 1],
     Graphics[Circle[{x0, y0}, r]]]
    

    enter image description here