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

查看:1505
本文介绍了如何在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?

推荐答案

别笑了,但最简单的方法是使用

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,即[x y] = [1 1]. 宽度高度等于圆的直径,因此width = 2*r; height = width;

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天全站免登陆