Intersection of circle chords
Afficher commentaires plus anciens
The following code contains 3 circles, the lines from each pair of circle's intersections (with circcirc fxn), the slope/y-intercepts for each of the 3 lines, and the intersections themselves (with plotted lines to confirm visually). I cannot figure out why the bjk intercept is approximately .158305 off from what it is supposed to be, and that is what I require help with. What could be causing this?
clc
clear all
% circle centers/radii
xCenterk = 5;
yCenterk = 2;
xCenteri = 5;
yCenteri = 5;
xCenterj = 3;
yCenterj = 3;
x=0:.001:100;
y=0:.001:100;
theta = 0 : 0.001 : 2*pi;
radiusk = 1.5;
radiusi = 2;
radiusj = 1.5;
%generate 3 circles with parameters above.
xk = radiusk * cos(theta) + xCenterk;
yk = radiusk * sin(theta) + yCenterk;
xi = radiusi * cos(theta) + xCenteri;
yi = radiusi * sin(theta) + yCenteri;
xj = radiusj * cos(theta) + xCenterj;
yj = radiusj * sin(theta) + yCenterj;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%plotting each circle pair's intersections (or chord)%%%%%%%%%%%%%%%%%%%%
[xoutij,youtij] = circcirc(xCenteri,yCenteri,radiusi,xCenterj,yCenterj,radiusj);
mapshow(xoutij,youtij,'DisplayType','point','Marker','o')
plot(line([xoutij(1,1) xoutij(1,2)],[youtij(1,1) youtij(1,2)]))
[xoutik,youtik] = circcirc(xCenteri,yCenteri,radiusi,xCenterk,yCenterk,radiusk);
mapshow(xoutik,youtik,'DisplayType','point','Marker','o')
plot(line([xoutik(1,1) xoutik(1,2)],[youtik(1,1) youtik(1,2)]))
[xoutjk,youtjk] = circcirc(xCenterj,yCenterj,radiusj,xCenterk,yCenterk,radiusk);
mapshow(xoutjk,youtjk,'DisplayType','point','Marker','o')
plot(line([xoutjk(1,1) xoutjk(1,2)],[youtjk(1,1) youtjk(1,2)]))
hold on;
% each lines slope
slopeij = @(line) (youtij(1,2) - youtij(1,1))/(xoutij(1,2) - xoutij(1,1));
mij = slopeij(line([xoutij(1,1) xoutij(1,2)],[youtij(1,1) youtij(1,2)]));
slopeik = @(line) (youtik(1,2) - youtik(1,1))/(xoutik(1,2) - xoutik(1,1));
mik = slopeik(line([xoutik(1,1) xoutik(1,2)],[youtik(1,1) youtik(1,2)]));
slopejk = @(line) (youtjk(1,2) - youtjk(1,1))/(xoutjk(1,2) - xoutjk(1,1));
mjk = slopejk(line([xoutjk(1) xoutjk(2)],[youtjk(1) youtjk(2)]));
% each lines y-intercept (round is used as a makeshift catch for slope = 0)
if round(100*mij)==0;
bij = youtij(1,1);
else
interceptij = @(line,m) xoutij(1,2) - m*xoutij(1,1);
bij = interceptij(line([xoutij(1,1) xoutij(1,2)],[youtij(1,1) youtij(1,2)]),mij);
end
if round(100*mik)==0;
bik = youtik(1,1);
else
interceptik = @(line,m) xoutik(1,2) - m*xoutik(1,1);
bik = interceptik(line([xoutik(1,1) xoutik(1,2)],[youtik(1,1) youtik(1,2)]),mik);
end
if round(100*mjk)==0;
bjk = youtjk(1,1);
else
interceptjk = @(line,m) xoutjk(1,2) - m*xoutjk(1,1);
bjk = interceptjk(line([xoutjk(1,1) xoutjk(1,2)],[youtjk(1,1) youtjk(1,2)]),mjk);
end
%%%Plotting intersection points %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x1intersect = (bik-bij)/(mij-mik);
y1intersect = mij*x1intersect + bij;
x2intersect = (bjk-bij)/(mij-mjk);
y2intersect = mij*x2intersect+bij;
x3intersect = (bjk-bik)/(mik-mjk);
y3intersect = mjk*x3intersect+bjk;
plot(x1intersect,y1intersect,'marker','o');
plot(x2intersect,y2intersect,'marker','o');
plot(x3intersect,y3intersect,'marker','o');
axis equal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
aij=0:.01:10;
b3=mij*aij+bij;
plot(aij,b3,'m');
axis equal
aik=0:.01:10;
b3=mik*aik+bik;
plot(aik,b3,'m');
axis equal
ajk=0:.01:10;
b3=mjk*ajk+bjk;
plot(ajk,b3,'m');
axis equal
plot(xk, yk,'b',xi,yi,'r',xj,yj,'c');
axis equal;
hold on;
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Type Identification dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!