## create polygons

Community contributed macros

Moderator: shela

owen
Site Admin
Posts: 16
Joined: Thu Apr 13, 2017 12:14 pm

### create polygons

Create polygons by defining the number of sides and side length.

Code: Select all

``````Declare Sub create_polygon(pnos As Integer, side_length As Double)
Dim Shared As Double pi
Dim As Integer number_of_polygon_sides
Dim As Double polygon_side_length
pi = 4 * Atn(1)

number_of_polygon_sides=13
polygon_side_length=100

create_polygon(number_of_polygon_sides, polygon_side_length)

Sub create_polygon(pnos As Integer, side_length As Double)
Dim As Double psa,pradius,papothem,pcenterx,pcentery,psai0,psai1,pptx1,ppty1,pptx2,ppty2
Dim As Integer i
psa=360/pnos
pradius=side_length/(2*Sin(pi/pnos))
papothem=Sqr(pradius^2-(side_length/2)^2)
pcenterx=side_length/2
pcentery=papothem
For i=0 To pnos-1
psai0=psa*i
psai1=psa*(i+1)
pptx1=pcenterx+cos(psai0*pi/180)*pradius
ppty1=pcentery+Sin(psai0*pi/180)*pradius
pptx2=pcenterx+cos(psai1*pi/180)*pradius
ppty2=pcentery+Sin(psai1*pi/180)*pradius
Line(pptx1,ppty1)-(pptx2,ppty2)
Next
End Sub

``````

### Who is online

Users browsing this forum: No registered users and 1 guest