matlab中circle函数_如何在Matlab中绘制圆?

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

but set the curvature of the rectangle to 1!

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 ]

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值