from a circle to polygon

17 Ansichten (letzte 30 Tage)
Mohamed soliman
Mohamed soliman am 21 Okt. 2021
Kommentiert: Mohamed soliman am 22 Okt. 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

Akzeptierte Antwort

Scott MacKenzie
Scott MacKenzie am 21 Okt. 2021
Bearbeitet: Scott MacKenzie am 21 Okt. 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 Kommentare
Mohamed soliman
Mohamed soliman am 21 Okt. 2021
Thanks a lot for your help.
BR
Mohamed
Scott MacKenzie
Scott MacKenzie am 21 Okt. 2021
You're welcome. Glad to help. Have fun.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Steven Lord
Steven Lord am 21 Okt. 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 Kommentare
Mohamed soliman
Mohamed soliman am 22 Okt. 2021
Thanks @Steven Lord for your help.
Mohamed soliman
Mohamed soliman am 22 Okt. 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Elementary Polygons finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by