Math Programming: Trig/Geometry[Python]

Genesis [Fromwarriors]
11 years ago

0

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()  

Image

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?

0replies
1voice
188views
1image
You must be logged in to reply to this discussion. Login
1 of 1

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss