Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: tangent to circles curve fitting Date: Thu, 23 Dec 2010 09:26:04 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 119 Message-ID: <iev4jc$s5s$1@fred.mathworks.com> References: <gp3aei$l81$1@fred.mathworks.com> <iettmd$9k4$1@fred.mathworks.com> <ieu0k4$itm$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-03-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1293096364 28860 172.30.248.38 (23 Dec 2010 09:26:04 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Thu, 23 Dec 2010 09:26:04 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2664468 Xref: news.mathworks.com comp.soft-sys.matlab:697782 Well, im having problems when those points are not collinear. Probably ive wrote it wrong. For example, %Points and radius %b1 = [p1,q1] r1; %b2 = [p2,q2] r2; %b3 = [p3,q3] r3; p1 = 1; p2 = 4; p3 = 10; q1 = 0; q2 = 0; q3 = 0; r1 = 0.5; r2 = 2; r3 = 3; %Get tangent for consecutive circles d2 = (p2-p1)^2+(q2-q1)^2; r = sqrt(d2-(r2-r1)^2); s = ((q2-q1)*r+(p2-p1)*(r2-r1))/d2; c = ((p2-p1)*r-(q2-q1)*(r2-r1))/d2; x1 = p1-r1*s; y1 = q1+r1*c; x2 = p2-r2*s; y2 = q2+r2*c; d2a = (p3-p2)^2+(q3-q2)^2; ra = sqrt(d2a-(r3-r2)^2); sa = ((q3-q2)*ra+(p3-p2)*(r3-r2))/d2a; ca = ((p3-p2)*ra-(q3-q2)*(r3-r2))/d2a; x2a = p2-r2*sa; y2a = q2+r2*ca; x3 = p3-r3*sa; y3 = q3+r3*ca; %Draw the circle THETA=linspace(0,pi,100); RHO=ones(1,100)*r1; [X,Y] = pol2cart(THETA,RHO); X=X+p1; Y=Y+q1; H=plot(X,Y,'r-'); axis square; hold on THETA=linspace(0,pi,100); RHO=ones(1,100)*r2; [X,Y] = pol2cart(THETA,RHO); X=X+p2; Y=Y+q2; H=plot(X,Y,'g-'); axis square; hold on THETA=linspace(0,pi,100); RHO=ones(1,100)*r3; [X,Y] = pol2cart(THETA,RHO); X=X+p3; Y=Y+q3; H=plot(X,Y,'g-'); axis square; hold on %XT = [x1 x2]; %YT = [y1 y2]; %line(XT,YT); %Draw the tangent Y = 0:0.1:10; Q = [x1 1; x2 1]; E = [y1;y2]; T = Q\E; Z = T(1)*Y + T(2); plot(Y,Z); hold on Y1 = 0:0.1:10; Q1 = [x2a 1; x3 1]; E1 = [y2a;y3]; T1 = Q1\E1; Z1 = T1(1)*Y1 + T1(2); plot(Y1,Z1); hold on %Plot all the curves axis equal; axis([0 12 0 5]); grid on plot(l1,l2,Z,Z1,'g.-'); thanks in advance "John D'Errico" <woodchips@rochester.rr.com> wrote in message <ieu0k4$itm$1@fred.mathworks.com>... > "Camp Camp" wrote in message <iettmd$9k4$1@fred.mathworks.com>... > > Hi guys, > > I'm using this question as cue for my own... > > i have also a series of consecutive circles, defined by someone the center and radius. But this must follow the rule thats is: the second circle has to have radius greater than first, and third has to have radius greater than second. I know that this could be a system with multiple solutions, but is there any possibilities to have a tangent to those 3 circles? Something like a fit linear. > > > > So what stops you from finding the lines that are tangent > to consecutive circles? Since you tell us that already KNOW > the radii for these circles, then just check to see if the lines > are collinear. If you don't know the radii of the circles, > then the problem is trivial. > > What is the problem here? > > John