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.
In my case, I have the following conditions:
- problem in first quadrant: x>0, y>0
- line y=m1*x+b1 with m1<=0, b1>=0
- line y=m2*x+b2 with m2 < m1, b2>b1
- circle centre above y=m1*x+b1, so y0>y1
- circle centre at r.h.s. of y=m2*x+b2, so x0>x2
- circle tangent to line y=m1*x+b1, so (y1-y0)/(x1-x0)=-1/m1
- circle tangent to line y=m2*x+b2, so (y2-y0)/(x2-x0)=-1/m2
I computed the following in SageMath:
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?
Without knowing
m1, b1, m2, b2, ryou cannot tell whether you even have solutions in the first quadrant. So in a way I believe your setup is too constrained. The fact that Sage by default assumes that numbers can be complex makes things even harder.Honestly I'd go about this a different way. Since the center of the circle has distance $r$ from your first line, it has to be on a line parallel to your first line but with a distance of $r$ between them. The same holds for the second line. So the center of the circle is essentially at the point where two parallels intersect.
With this approach, you can build all the magic around which of the solutions you want into the choice of which of the two possible parallels you want for each of your lines. Then it's a simple intersection of lines after that.