plotting circles

856 ビュー (過去 30 日間)
Yasmin Tamimi
Yasmin Tamimi 2011 年 3 月 12 日
コメント済み: Michelle Hirsch 2023 年 12 月 11 日
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
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
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
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
Özgür Saglam
Özgür Saglam 2020 年 5 月 3 日
Thank you very much!

サインインしてコメントする。

その他の回答 (3 件)

Michelle Hirsch
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
Royi Avital 2023 年 12 月 10 日
@Michelle Hirsch, It would be great if it had the DisplayName property like most other objects.
It makes easier when adding it to the legend.
Michelle Hirsch
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.

サインインしてコメントする。


Chad Greene
Chad Greene 2014 年 8 月 21 日
This'll do the job.

Image Analyst
Image Analyst 2016 年 1 月 20 日
編集済み: Image Analyst 2022 年 4 月 15 日
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

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by