如何在Matlab中绘制一个圆? [英] How to plot a circle in Matlab?

查看:47
本文介绍了如何在Matlab中绘制一个圆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在知道圆心和半径的情况下在 Matlab 中绘制圆?我试过 circles() 这似乎不起作用,因为我的 Matlab 版本没有它.我知道我可以使用 Rectangle 函数来这样做,但这是一种相当复杂的方法,因为我每次都需要计算出最左边的点.

I would like to know how can I graph circles in Matlab knowing the center and radius? I have tried circles() which does not seem to work because my Matlab version does not have it. I know I can use the Rectangle function to do so but it is a rather complex way of doing it as I would need to work out the leftmost point everytime.

难道没有更简单的方法可以让我在知道圆心和半径的情况下画圆吗?

Isn't there a more simple way for me to draw a circle JUST knowing center and radius?

推荐答案

别笑,但最简单的方法是使用 rectangle 函数,确实;)

Don't laugh, but the easiest would be to use the rectangle function, indeed ;)

%// radius
r = 2;

%// center
c = [3 3];

pos = [c-r 2*r 2*r];
rectangle('Position',pos,'Curvature',[1 1])
axis equal

但是将矩形的曲率设置为1

but set the curvature of the rectangle to 1!

position 向量定义了矩形,前两个值 xy 是矩形的左下角.最后两个值定义了矩形的宽度和高度.

The position vector defines the rectangle, the first two values x and y are the lower left corner of the rectangle. The last two values define width and height of the rectangle.

pos = [ [x y] width height ]

圆的左下 - 是的,这个圆有角,虽然是假想的 - 是中心 c = [3 3] 减去半径 r = 2[xy] = [1 1].宽度高度等于圆的直径,所以width = 2*r;高度 = 宽度;

The lower left corner of your circle - yes, this circle has corners, imaginary ones though - is the center c = [3 3] minus the radius r = 2 which is [x y] = [1 1]. Width and height are equal to the diameter of the circle, so width = 2*r; height = width;

如果您不喜欢上述解决方案的流畅性,则无法使用通过使用三角函数来绘制实际圆的明显方法.

In case you don't like the smoothness of the above solution, there is no way around using the obvious way of drawing an actual circle by use of trigonometric functions.

%// number of points
n = 1000;

%// running variable
t = linspace(0,2*pi,n);

x = c(1) + r*sin(t);
y = c(2) + r*cos(t);

%// draw line
line(x,y)

%// or draw polygon if you want to fill it with color
%// fill(x,y,[1,1,1])
axis equal

这篇关于如何在Matlab中绘制一个圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆