# Iterative Solution

3 messages
Open this post in threaded view
|

## Iterative Solution

 I was watching a machinist make a part.  The portion of the part I was interested in consisted of a circle and a line.  The machinist wanted to locate a tool such that it was tangent to the line and the circle. I used an iterative method to calculate the location of the center of the tool circle.  This took 71 iterations.  Must be a better method. Tom Dean ## given a circle, C1, ##     center (3+1/2)/2, (3+1/2)/2+1+1/4, radius (3+1/2)/2 ## and a line, L1, ##     x=(3+1/2)/2 - (3/4+20/1000)/2 - 1/2, ## find a circle, CT1, of radius 1/8 such that it is tangent to both ## L1 and C1.  CT1 is outside C1 and between L1 and the origin. ## The x value of center(CT1) is ##      (3+1/2)/2 - (3/4+20/1000)/2 - 1/2 - 1/8. ## The y value of center(CT1) is that value that results in the ## distance from center(C1) to center(CT1) is equal to ##      radius(C1) + radius(CT1) ## Start with y = 0 and increase y until ##    d = distance( center(C1) - center(CT1) ) ##      = sqrt( ((3+1/2)/2 - 1/8)^2 + ((3+1/2)/2+1+1/4 - x_value)^2) ##    d - ( (3+1/2)/2 + 1/8 ) = 0 function [x1, y1] = find_loc()    x0 = (3+1/2)/2; y0 = (3+1/2)/2+1+1/4; r0 = (3+1/2)/2;    x1 = (3+1/2)/2 - (3/4+20/1000)/2 - 1/2 - 1/8; y1 = 0; r1 = 1/8;    ## maple answer y1 == 1.420276923    dy = 1;    d = sqrt( (x0 - x1)^2 + (y0 - y1)^2);    err = d - (r0 + r1);    s = sign(err);    iters = 1;    while (abs(err) > 1e-15)      if (sign(err) == s);        y1 += s*dy;      else        s = sign(err);        dy /= 10;        y1 += s*dy;      endif      d = sqrt( (x0 - x1)^2 + (y0 - y1)^2);      err = d - (r0 + r1);      iters++;    endwhile    printf("iterations %d\n", iters); endfunction;