【发布时间】:2021-02-26 17:43:17
【问题描述】:
我需要找出两个圆的交点。我有每个圆的中心点和半径。我需要在 MATLAB 中完成。任何帮助将不胜感激。
【问题讨论】:
我需要找出两个圆的交点。我有每个圆的中心点和半径。我需要在 MATLAB 中完成。任何帮助将不胜感激。
【问题讨论】:
假设一个三角形ABC,其中A和B是圆心,C是一个或另一个交点。 a、b 和 c 是与相应角相对的边。 alpha、beta 和 gamma 分别是与 A、B 和 C 相关的角度。
那么,b^2+c^2 - 2*bccos(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
【讨论】:
% 作为 cmets 的标记。为了获得正确的突出显示,我使用%# - 这样它看起来很漂亮,可以直接复制粘贴到 Matlab
找出圆的方程。确保考虑平方根的负数,否则你只会有一个半圆。
设置两个圆的方程彼此相等。
【讨论】:
这是一个使用两个文件交换提交的简单代码:第一个 - 绘制圆圈,第二个 - 查找交叉点(链接如下)。
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
【讨论】:
函数CIRCCIRC 会为你做这件事。
[xout,yout] = circcirc(x1,y1,r1,x2,y2,r2)
这将为您提供两个交点。
【讨论】:
我在这里粘贴罗杰斯塔福德的答案。 (参见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];
【讨论】: