import math
def main():
print "Please enter the type of n-gon. Ex: for hexagon, put 8 because it has 8 sides."
n = input("> ")
print "Please enter the base length for the regular polygon."
b = input("> ")
b2 = b-2
#Algorithm
print("Process: \n")
a = 180*(n-2)/n
print('Angle Degrees on every angle:' ), a
a1 = a/2
print('Angle degrees for half of an angle to us in triangle: '), a1
trig = math.tan(a1)*b2
print('Height: '), trig
areaofTriangle = trig*b/2
print('Area of one triangle(Equilateral): '), areaofTriangle
area = areaofTriangle*n
print('\nThe area of your polygon is: '), area
main()
What this does:
First it asks you for the number of sides on a regular(symmetrical) polygon. Then asks for the base of the polygon. The algorithm does this: it takes the number of sides and subtracts two and multiplies it by 180, and divides it by n, which gives you the angle measurements of each angle on the polygon. next it uses the angle and divides it by two, to use it on an imaginary equilateral triangle In the polygon. Then it uses a tangent ratio to get the height of 1 right triangle inside of the equilateral one. After that has happened, it gets the area of the equilateral triangle and multiplies it by n(number of sides/triangles) to get the area of the whole polygon. Pretty neat, eh?