How to draw three circles with centers and radii given?

조회 수: 4 (최근 30일)
Curious
Curious 2022년 6월 27일
댓글: Image Analyst 2022년 7월 13일
I have entered the data in this program and tried to draw three circles on same figure which would then give me their intersection in x and y but I can't cuz there is no command for circles. Kindly assist.
clc
clear all
close all
x1=2; y1=8; r1=10;
x2=5; y2=5; r2=12;
x3=4; y3=9; r3=9;
function circle(x,y,r);
h=plot(x
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.

Error in connector.internal.fevalMatlab

Error in connector.internal.fevalJSON
drawCircle([x1;x2], r1, 'r');
drawCircle([x2;y2], r2, 'g');
drawCircle([x3;y3], r3, 'b');
x=((y2-y1)*((y2^2-y1^2)+(x2^2-x1^2)+(r1^2-r2^2))- (y1-y2)*((y3^2-y2^2)+(x3^2-x2^2)+(r2^2-r3^2)))/2*((x1-x2)*(y2-y3)-(x2-x3)*(y1-y2))
y=((x2-x3)*((x2^2-x1^2)+(y2^2-y1^2)+(r1^2-r2^2))- (x1-x2)*((x3^2-x2^2)+(y3^2-y2^2)+(r2^2-r3^2)))/2*((y1-y2)*(x2-x3)-(y2-y3)*(x1-x2))
plot(x,y)

채택된 답변

Image Analyst
Image Analyst 2022년 6월 27일
"I can't cuz there is no command for circles" <== there is if you have the Image Processing Toolbox.
x1=2; y1=8; r1=10;
x2=5; y2=5; r2=12;
x3=4; y3=9; r3=9;
viscircles([x1, y1], r1, 'Color', 'r');
viscircles([x2, y2], r2, 'Color', 'g');
viscircles([x3, y3], r3, 'Color', 'b');
As far as determining intersection points, you'll have to use math for that. Or else use a distance formula on your (x,y) arrays.
  댓글 수: 2
Curious
Curious 2022년 7월 13일
x1=2; y1=8; r1=10;
x2=5; y2=5; r2=12;
x3=4; y3=9; r3=9;
viscircles([x1, y1], r1, 'Color', 'r');
viscircles([x2, y2], r2, 'Color', 'g');
viscircles([x3, y3], r3, 'Color', 'b');
hold on
x=(((x2-x3)*((x2^2-x1^2)+(y2^2-y1^2)+(r1^2-r2^2))-(x1-x2)*((x3^2-x2^2)+(y3^2-y2^2)+(r2^2-r3^2))))/(2*((y1-y2)*(x2-x3)-(y2-y3)*(x1-x2)))
x = -14.8889
y=(((y2-y3)*((y2^2-y1^2)+(x2^2-x1^2)+(r1^2-r2^2))-(y1-y2)*((y3^2-y2^2)+(x3^2-x2^2)+(r2^2-r3^2))))/(2*((x1-x2)*(y2-y3)-(x2-x3)*(y1-y2)))
y = -4.5556
plot(x , y,'r*')
I have tried this code of yours with a mathematical formula for intersection point but it's not giving the intersection. Any thoughts?
Image Analyst
Image Analyst 2022년 7월 13일
You have to get the equation of a circle and set them equal to each other, like
(x-x1c).^2 + (y - y1c).^2 - R1^2 = (x-x2c).^2 + (y - y2c).^2 - R2^2
Then solve for x and y. It might be easier to do numerically than analytically but maybe not. You'd have to multiply it out, collect terms, etc. just like you'd solve any equation.

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

추가 답변 (1개)

KSSV
KSSV 2022년 6월 27일
x1=2; y1=8; r1=10;
x2=5; y2=5; r2=12;
x3=4; y3=9; r3=9;
th = linspace(0,2*pi) ;
x = cos(th) ; y = sin(th) ;
figure
hold on
plot(x1+r1*cos(th),y1+r2*sin(th)) ;
plot(x2+r2*cos(th),y3+r2*sin(th)) ;
plot(x3+r1*cos(th),y3+r3*sin(th)) ;
axis equal

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by