plotting circles
조회 수: 840 (최근 30일)
이전 댓글 표시
How can I plot circles, same radius and different centers, all in one graph. I used the following command to draw +,o,diamond: plot (x,y,'ro',u,v,'gd',A,B,'b+'); where x,y,u,v,A,B are all row vectors. And I want to add circles to that plot where the o will be the center.
댓글 수: 1
fatima ibrahim
2020년 2월 29일
function draw_circle1(x,y,R,c)
t =0:0.05:6.28;
x1 = (x +R*cos(t))';
y1= (x +R*sin(t))';
채택된 답변
Paulo Silva
2011년 3월 12일
Here's a function to draw circles:
function circle(x,y,r)
%x and y are the coordinates of the center of the circle
%r is the radius of the circle
%0.01 is the angle step, bigger values will draw the circle faster but
%you might notice imperfections (not very smooth)
ang=0:0.01:2*pi;
xp=r*cos(ang);
yp=r*sin(ang);
plot(x+xp,y+yp);
end
If you want to add circles you must insert the command
hold on
before the circles being added.
댓글 수: 8
Rik
2020년 5월 3일
It's the step size. You can use the colon in two ways when you create an array:
start:stop
start:step:stop
추가 답변 (3개)
Michelle Hirsch
2016년 1월 29일
It's counter-intuitive, but this is actually really easy with the rectangle function. From the rectangle documentation :
pos = [2 4 2 2];
rectangle('Position',pos,'Curvature',[1 1])
axis equal
댓글 수: 5
Royi Avital
2023년 12월 10일
It makes easier when adding it to the legend.
Michelle Hirsch
2023년 12월 11일
@Royi Avital I think it's more than just adding DisplayName - annotations like rectangle (intentionally) don't show up in legend since they are meant to be annotations, not data. Are you interested in being able to include annotations in legend? If so, please share more about your use case so I make sure we understand what you are thinking.
Image Analyst
2016년 1월 20일
편집: Image Analyst
2022년 4월 15일
There is now a function called viscircles(): http://www.mathworks.com/help/images/ref/viscircles.html?s_tid=srchtitle
numCircles = 15;
x = 5 + randi(95, numCircles, 1);
y = 5 + randi(95, numCircles, 1);
radius = 2 * ones(numCircles, 1);
viscircles([x, y], radius);
grid on;
axis equal
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!