[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Iterative Solution
From: |
Thomas D. Dean |
Subject: |
Iterative Solution |
Date: |
Mon, 27 Aug 2018 23:17:39 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 |
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;
- Iterative Solution,
Thomas D. Dean <=