How to Draw a Pentagon or Polygon by Using Function

조회 수: 23(최근 30일)
Özgür Alaydin
Özgür Alaydin 2023년 3월 15일
댓글: Özgür Alaydin 2023년 3월 16일
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?
a=10; %% size of pentagon
polyg = 5;
Nx=50; Ny=50;
Mx=50; My=50;
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;


Steven Lord
Steven Lord 2023년 3월 15일
Why not just use nsidedpoly?
P = nsidedpoly(5);
axis equal
  댓글 수: 3
Ö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.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by