필터 지우기
필터 지우기

Need a script to plot a circle with given radius and center

조회 수: 51 (최근 30일)
Manu Manu
Manu Manu 2014년 3월 16일
댓글: Image Analyst 2021년 8월 31일
I need some help guys! Need a script to plot a circle with center(5,7) and radius 3. I have these:
clear clc
r=3;
t=0:pi/24:2*pi;
x=r*cos(t);
y=r*sin(t);
plot(x,y,x,y)
grid on
But only the radius works.. help please.

채택된 답변

Image Analyst
Image Analyst 2014년 3월 16일
편집: Image Analyst 2014년 3월 16일
Here's one way from the FAQ that is most similar to yours:
xCenter = 5;
yCenter = 7;
theta = 0 : 0.01 : 2*pi;
radius = 3;
x = radius * cos(theta) + xCenter;
y = radius * sin(theta) + yCenter;
plot(x, y);
axis square;
xlim([0 10]);
ylim([0 12]);
grid on;
axis equal;
  댓글 수: 3
picheri naveen
picheri naveen 2021년 8월 31일
Why we are taking theta = 0:0.01:2*pi
Image Analyst
Image Analyst 2021년 8월 31일
@picheri naveen You can choose whatever angle increment you want. If you want bigger angle increments, change 0.01 to 0.3 or whatever you want. Or if you want to specify the number of segments on the circle, you can use linspace():
startAngle = 0;
endAngle = 2 * pi;
numberOfSegments = 360; % Whatever you want.
theta = linspace(startAngle, endAngle, numberOfSegments);
If the starting and ending angle are not 0 and 2*pi, then you'll get a partial circle (arc). And of course if your ending angle is more than 2*pi than your starting angle, you'll get some overlap.
The more you choose, the smoother the circle will be. Less will make it more polygon-like. For example if you had only 6 segments, it would look like a hexagon instead of a circle.

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

추가 답변 (2개)

Image Analyst
Image Analyst 2020년 6월 11일
Here's another way
viscircles([5,7], 3);
  댓글 수: 2
Tamara del Águila
Tamara del Águila 2021년 5월 26일
but which units does viscircle use? When I draw a circular roi with drawcircle, and then I plot in the obtained coordinates a circle with viscircle, the size do not match...
Image Analyst
Image Analyst 2021년 5월 26일
I believe they both use units of whatever the axes control is using. I think they should be the same. Post a small snippet of your code showing how you compute "size" and a screenshot showing the different circle sizes.

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


Alamgir Khan
Alamgir Khan 2020년 6월 11일
편집: Alamgir Khan 2020년 6월 11일
In parametric form of the circle of radius 1, at centred(0,0) x=cos(2 pi×t) and y=sin(2pi ×t) using ezplot command

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by