How to draw three circles with centers and radii given?

4 visualizzazioni (ultimi 30 giorni)
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)

Risposta accettata

Image Analyst
Image Analyst il 27 Giu 2022
"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 Commenti
Curious
Curious il 13 Lug 2022
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 il 13 Lug 2022
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.

Accedi per commentare.

Più risposte (1)

KSSV
KSSV il 27 Giu 2022
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

Community Treasure Hunt

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

Start Hunting!

Translated by