2011-03-08 277 views
1

我需要找出兩個圓的相交點。我有中心點和每個圓的半徑。我需要在MATLAB中完成。任何幫助將不勝感激。MATLAB中兩個圓相交點

回答

2

找到圓的方程。確保考慮平方根的負數,否則你只會有一個半圓。

將兩個圓的方程設爲等於彼此。

+0

謝謝..我知道如何做到這一點的幾何形狀,但是不知道該怎麼辦呢Matlab的,因爲我很新的Matlab的。 – Pow 2011-03-08 22:28:22

3

假設一個三角形ABC,其中A和B是圓的中心,C是一個或另一個交點。 a,b和c是與相應角落相對的側面。 α,β和γ分別是與A,B和C相關的角度。

然後,b^2 + c^2 -2 * b c cos(alpha)= a^2。瞭解阿爾法(或餘弦),你可以找到C的位置

A = [0 0]; %# center of the first circle 
B = [1 0]; %# center of the second circle 
a = 0.7; %# radius of the SECOND circle 
b = 0.9; %# radius of the FIRST circle 
c = norm(A-B); %# distance between circles 

cosAlpha = (b^2+c^2-a^2)/(2*b*c); 

u_AB = (B - A)/c; %# unit vector from first to second center 
pu_AB = [u_AB(2), -u_AB(1)]; %# perpendicular vector to unit vector 

%# use the cosine of alpha to calculate the length of the 
%# vector along and perpendicular to AB that leads to the 
%# intersection point 
intersect_1 = A + u_AB * (b*cosAlpha) + pu_AB * (b*sqrt(1-cosAlpha^2)); 
intersect_2 = A + u_AB * (b*cosAlpha) - pu_AB * (b*sqrt(1-cosAlpha^2)); 

intersect_1 = 
    0.66  -0.61188 
intersect_2 = 
    0.66  0.61188 

enter image description here

+0

你爲什麼不把#換成%;-)。 – eat 2011-03-08 21:58:18

+0

@eat:咦?我不明白你的意思。 – Jonas 2011-03-08 22:00:30

+0

大概吃就是問爲什麼你使用%#評論。 – yuk 2011-03-08 23:37:55

0

下面是使用兩個文件交換提交一個簡單的代碼:第一 - 畫圓,第二 - 找到交點(以下鏈接)。

clf 
N=30; % circle resolution as the number of points 
hold on 
% draw 1st circle at (0,0) radius 5 and get X and Y data 
H1=circle([0 0],5,N); 
X1=get(H1,'XData'); 
Y1=get(H1,'YData'); 

% draw 2nd circle at (2,5) radius 3 and get X and Y data 
H2=circle([2 5],3,N); 
X2=get(H2,'XData'); 
Y2=get(H2,'YData'); 

% find intersection points 
[x,y]=intersections(X1,Y1,X2,Y2,0); 
% and plot them as red o's 
plot(x,y,'ro') 
hold off 
axis equal 
  1. CIRCLE
  2. Fast and Robust Curve Intersections

enter image description here