from a circle to polygon

17 vues (au cours des 30 derniers jours)
Mohamed soliman
Mohamed soliman le 21 Oct 2021
Commenté : Mohamed soliman le 22 Oct 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

Réponse acceptée

Scott MacKenzie
Scott MacKenzie le 21 Oct 2021
Modifié(e) : Scott MacKenzie le 21 Oct 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 commentaires
Mohamed soliman
Mohamed soliman le 21 Oct 2021
Thanks a lot for your help.
BR
Mohamed
Scott MacKenzie
Scott MacKenzie le 21 Oct 2021
You're welcome. Glad to help. Have fun.

Connectez-vous pour commenter.

Plus de réponses (1)

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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Elementary Polygons dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by