필터 지우기
필터 지우기

Tangent to two circles

조회 수: 18 (최근 30일)
Ramin
Ramin 2014년 11월 16일
댓글: Ramin 2014년 11월 17일
Hello everyone!
Have spent the enitre few days trying to figure this problem out, but Im going nowhere.
Problem is I have the coordinates for two circles C1(-1,1) and C2(2,2.5) with radius r1 = 1 and r2 = 1.5. Now I have to write a program that calculates the coordinates for the points of the outer common tangent (p1 and p2) to these two circles. I know there are many ways of doing so, one of them being that you write a system of equations with the help of these relations:
(p1-c1)*(p1-p2)=0 (the radius for the circles are perpendicular to the line between the circle centers)
(p2-c2)*(p1-p2)=0
and
Abs(p1-c1)^2=r1^2 (these conditions are so that the points are on the circles)
Abs(p2-c2)^2=r2^2
I'm thinking that you have to solve p1 and p2 from these equations but I just don't know how to do it. Please if anyone could help me I would be so very grateful!

채택된 답변

Roger Stafford
Roger Stafford 2014년 11월 17일
Here is a direct matlab solution to your problem, Ramin, that does not involve iterative solution of equations. It just uses simple geometry. Let C1 = [a1,b1] and C2 = [a2,b2] be the two circles' centers and r1 and r2 their respective radii.
a21 = a2-a1; b21 = b2-b1;
d2 = a21^2+b21^2;
r21 = (r2-r1)/d2;
s21 = sqrt(d2-(r2-r1)^2)/d2; % <-- If d2<(r2-r1)^2, no solution is possible
u1 = [-a21*r21-b21*s21,-b21*r21+a21*s21]; % Left unit vector
u2 = [-a21*r21+b21*s21,-b21*r21-a21*s21]; % Right unit vector
L1 = [a1,b1]+r1*u1; L2 = [a2,b2]+r2*u1; % Left line tangency points
R1 = [a1,b1]+r1*u2; R2 = [a2,b2]+r2*u2; % Right line tangency points
As you move from C1 toward C2, L1 and L2 will be the two points of outer tangency of the line to the left and R1 and R2 the two tangency points of the line to the right.
  댓글 수: 1
Ramin
Ramin 2014년 11월 17일
Thanks so much for the help! Can finally solve this one now

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

pietro
pietro 2014년 11월 16일
편집: pietro 2014년 11월 16일
Hi,
the 3rd and 4th equations shouldn't be as the folliwing, right?
p1^2-c1^2=r1^2
p2^2-c2^2=r2^2
you can use fsolve or solve if you need a symbolic solution. Anyway I think it might be easily solved by hand.
  댓글 수: 2
Ramin
Ramin 2014년 11월 16일
편집: Ramin 2014년 11월 16일
Oh I seem to have written it wrong. The brackets are not visible but I fixed it now.
But anyway thanks for the answer! I got some help from a friend and solved the problem in the end.
Matt J
Matt J 2014년 11월 16일
The equations should have reduced to linear ones, easily solvable using mldivide.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by