Question: Intersection of a line and two circles

This started as calculating the location of a machine tool bit that is tangent to a line and a circle.  I watched the part being made.  The machinist moved the tool bit manually until it touched straight and circular markings on a aluminum blank.  Repeating this two times, recording the x-y values, the g-code was altered and the CNC machine started to make the part.  Should be a simple calculation, right?

Well, not for me:

restart; with(geometry):
## Find the (x, y) location of a machine mill path such that the tool is
## tangent to a line and a circle.
##
## Given a line, L1, and a circle, C1, find a circle, C4 tangent to
## both L1 and C1.  Choose the X value of C4 to be such that the
## center of C4 is between the intersection of L1 with the X axis and
## origin.
x0 := (3+1/2)/2;
x1 := x0; y1 := x0 + (1+1/4);
point('P1', x1, y1); ## center of the circle

circle('C2', [P1, x0]);

## X value for line L1
x3 := (3+1/2)/2-(3/4+20/1000)/2-1/2; y3 := 1+1/4; evalf([x3, y3]);
## points P2 and P3 lie on the line
point('P2', x3, 0); point('P3', x3, y3);
line('L1', [P2, P3]);

intersection('I1', L1, C2);
for s in I1 do print(evalf(coordinates(s))) end do;

tr := 1/8;  ## tool radius, radius of C4
## find P4 such that C4 is tangent to L1
x4 := x3 - tr;
## P4 moves parallel to L1
point('P4', x4, 'y4');
circle('C4', [P4, tr]);
Equation(C4); Equation(C2);
intersection('I2', C2, C4);
## fails

## The centerline of the part is at x = (3+1/2)/2 Another dimension of
## the part, is (3/4+20/1000), centered on the centerline.  A second
## dimension of the part is 1/2.  From the physical layout of the
## part, observe that
x_value := (3+1/2)/2 - (3/4+20/1000)/2 - 1/2 - tr: evalf(%);
eq1 := subs(x = x_value, Equation(C4)); eq2 := subs(x = x_value, Equation(C2));
sol := solve([eq1, eq2]); evalf(%);
evalf(sol);

## want the solution with the least y value for point P4
res1 := subs(sol[1], coordinates(P4));
res2 := subs(sol[2], coordinates(P4));

if evalf(res1[2]) < evalf(res2[2]) then
    soln := res1;
else
    soln := res2;
end if;
evalf(soln);

point('P8', soln); evalf(coordinates(P8));
circle('C8', [P8, 1/8]); evalf(Equation(C8)); evalf(Equation(C2));
## the intersect fails  Why?

intersection('I8', C2, C8);

evalf(coordinates(I8[1])); evalf(coordinates(I8[2]));

solve([Equation(C2), Equation(C8)]); evalf(%);
print("The location is", evalf(soln));

 

Please Wait...