from a circle to polygon

16 次查看(过去 30 天)
Hello All,
If I have a circle (x-a)^2 +(x-b)^2 = r^2 , is the any matlab function that converts this circle to polygon?
Thanks
Mohamed

采纳的回答

Scott MacKenzie
Scott MacKenzie 2021-10-21
编辑:Scott MacKenzie 2021-10-21
I know of no such formula, although no doubt one could be put together.
You can think of circle as a polygon with a large (infinite!) number of vertices. Reduce the number of vertices and the shape starts to look like a polygon. Using trig functions, here's one way to demonstrate this:
radius = 1;
tiledlayout(1,4);
nexttile;
n = 100; % number of vertices (+1)
theta = linspace(0,2*pi,n);
x = cos(theta) * radius;
y = sin(theta) * radius;
plot(x,y);
title(compose('Number of vertices = %d', n-1));
set(gca, 'xlim', [-1 1], 'ylim', [-1 1]);
nexttile;
n = 16; % number of vertices (+1)
theta = linspace(0,2*pi,n);
x = cos(theta) * radius;
y = sin(theta) * radius;
plot(x,y);
title(compose('Number of vertices = %d', n-1));
set(gca, 'xlim', [-1 1], 'ylim', [-1 1]);
nexttile;
n = 9; % number of vertices (+1)
theta = linspace(0,2*pi,n);
x = cos(theta) * radius;
y = sin(theta) * radius;
plot(x,y);
title(compose('Number of vertices = %d', n-1));
set(gca, 'xlim', [-1 1], 'ylim', [-1 1]);
nexttile;
n = 4; % number of vertices (+1)
theta = linspace(0,2*pi,n);
x = cos(theta) * radius;
y = sin(theta) * radius;
plot(x,y);
title(compose('Number of vertices = %d', n-1));
set(gca, 'xlim', [-1 1], 'ylim', [-1 1]);
  2 个评论
Mohamed soliman
Mohamed soliman 2021-10-21
Thanks a lot for your help.
BR
Mohamed
Scott MacKenzie
Scott MacKenzie 2021-10-21
You're welcome. Glad to help. Have fun.

请先登录,再进行评论。

更多回答(1 个)

Steven Lord
Steven Lord 2021-10-21
As @Scott MacKenzie stated, you can approximate a circle as a many-sided regular polygon. The nsidedpoly function will create such a many-sided polygon that you can plot or operate on.
for k = 1:6
subplot(2, 3, k)
P = nsidedpoly(3^k);
plot(P);
title(3^k + " sides")
end
  2 个评论
Mohamed soliman
Mohamed soliman 2021-10-22
I have a nother question, is there a function that , given a polygon: pgon2 = nsidedpoly(8,'Center',[5 0],'Radius',10); can automatically construct A and b matrices such that A.x<= b
i.e this polygon can be represented by a set of inequaltiy constraints
Best regards
Mohamed

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by