MATLAB中两个圆的交点

时间:2011-03-08 21:30:32

标签: matlab geometry

我需要找出两个圆圈的交叉点。我有中心点和每个圆的半径。我需要在MATLAB中完成它。任何帮助将不胜感激。

5 个答案:

答案 0 :(得分:3)

假设一个三角形ABC,其中A和B是圆的中心,C是一个或另一个交叉点。 a,b和c是与相应角相对的侧面。 alpha,beta和gamma分别是与A,B和C相关的角度。

然后,b ^ 2 + c ^ 2 - 2 * b c cos(alpha)= a ^ 2。知道alpha(或其余弦),你可以找到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

答案 1 :(得分:2)

找出圆的方程。确保考虑平方根的负数,否则你将只有一个半圆。

将两个圆的方程设置为彼此相等。

答案 2 :(得分: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
  3. enter image description here

答案 3 :(得分:0)

函数CIRCCIRC为您完成此任务。

[xout,yout] = circcirc(x1,y1,r1,x2,y2,r2)

这将为您提供两个交叉点。

http://www.mathworks.nl/help/map/ref/circcirc.html

答案 4 :(得分:0)

我在这里粘贴 Roger Stafford 的回答。 (参见link)如果圆圈之间没有交点,这也会打印。我想你可以在代码中计算出几何关系。

% P1 和 P2 是列向量 r1 和 r2 是它们各自的半径。 % P1 = [x1;y1]; P2 = [x2;y2];

d2 = sum((P2-P1).^2);
P0 = (P1+P2)/2+(r1^2-r2^2)/d2/2*(P2-P1);
t = ((r1+r2)^2-d2)*(d2-(r2-r1)^2);
if t <= 0
    fprintf('The circles don''t intersect.\n')
else
    T = sqrt(t)/d2/2*[0 -1;1 0]*(P2-P1);
    Pa = P0 + T; % Pa and Pb are circles' intersection points
    Pb = P0 - T;
end
Pint = [Pa, Pb];