from a circle to polygon

16 views (last 30 days)
Mohamed soliman
Mohamed soliman on 21 Oct 2021
Commented: Mohamed soliman on 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

Accepted Answer

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

Sign in to comment.

More Answers (1)

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

Sign in to comment.

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!