from a circle to polygon

19 visualizaciones (últimos 30 días)
Mohamed soliman
Mohamed soliman el 21 de Oct. de 2021
Comentada: Mohamed soliman el 22 de Oct. de 2021
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

Respuesta aceptada

Scott MacKenzie
Scott MacKenzie el 21 de Oct. de 2021
Editada: Scott MacKenzie el 21 de Oct. de 2021
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 comentarios
Mohamed soliman
Mohamed soliman el 21 de Oct. de 2021
Thanks a lot for your help.
BR
Mohamed
Scott MacKenzie
Scott MacKenzie el 21 de Oct. de 2021
You're welcome. Glad to help. Have fun.

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord
Steven Lord el 21 de Oct. de 2021
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 comentarios
Mohamed soliman
Mohamed soliman el 22 de Oct. de 2021
Thanks @Steven Lord for your help.
Mohamed soliman
Mohamed soliman el 22 de Oct. de 2021
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

Iniciar sesión para comentar.

Categorías

Más información sobre Elementary Polygons en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by