How to Draw a Pentagon or Polygon by Using Function

Dear all,
I want to draw a pentagon and am using the code given below.
Vb is the height of the pentagon. X and Y are the limits of the coordinates in the given directions.
The problem is: when i plot i am getting the pentagon but lengths are not equal as shown in figure.
How can i get a regular pentagon?
Vb=250;
a=10; %% size of pentagon
polyg = 5;
Nx=50; Ny=50;
Mx=50; My=50;
x=linspace(-Mx/2,Mx/2,Nx);
y=linspace(-My/2,My/2,Ny);
[X,Y]=meshgrid(x,y);
f1 = (abs(X)<a*sind((polyg-2)*180/polyg));
f2 = (X*cotd(360/polyg)-a<Y)...
.* (-X*cotd(360/polyg)-a<Y)...
.* (-X*cotd(360/polyg)+a>Y);
fx = f1.*f2;
V0 = (1-fx)*Vb;
surf(X,Y,V0);

回答 (1 件)

Steven Lord
Steven Lord 2023 年 3 月 15 日

1 投票

Why not just use nsidedpoly?
P = nsidedpoly(5);
plot(P);
axis equal

3 件のコメント

Özgür Alaydin
Özgür Alaydin 2023 年 3 月 15 日
I plot in 3d and also i needed as a function.
Steven Lord
Steven Lord 2023 年 3 月 15 日
So are you looking for a "column" with a pentagonal cross-section or are you looking for more of a dodecahedron?
P = nsidedpoly(5)
P =
polyshape with properties: Vertices: [5×2 double] NumRegions: 1 NumHoles: 0
P.Vertices
ans = 5×2
-0.5878 -0.8090 -0.9511 0.3090 0 1.0000 0.9511 0.3090 0.5878 -0.8090
Use whatever mechanism you see fit to apply various affine transformations to these coordinates. Cleve Moler has written some tools that may be of interest: Grafix 2.0.
Özgür Alaydin
Özgür Alaydin 2023 年 3 月 16 日
Not as i want because i will use integration after getting the coordinates of the pentagon.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMaterial Sciences についてさらに検索

質問済み:

2023 年 3 月 15 日

コメント済み:

2023 年 3 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by