find the surface area of a regular polygon circumscribed around a sphere in python

To find the surface area of a regular polygon circumscribed around a sphere, we need to find the surface area of the sphere and the surface area of the polygon. We can use the following formulae:

  • Surface area of a sphere = 4 * pi * R^2, where R is the radius of the sphere.
  • Surface area of a regular polygon = (n * a^2) / (4 * tan(pi/n)), where n is the number of sides of the polygon and a is the length of each side.

We can write a Python function to calculate the surface area of a regular polygon circumscribed around a sphere by taking the number of sides of the polygon and the radius of the sphere as inputs:

main.py
import math

def surface_area_reg_polygon_circumscribed_sphere(n, r):
    # Surface area of a sphere
    sphere_area = 4 * math.pi * r ** 2
    
    # Length of each side of the polygon
    a = 2 * r * math.sin(math.pi/n)
    
    # Surface area of the polygon
    polygon_area = (n * a ** 2) / (4 * math.tan(math.pi/n))
    
    # Surface area of the regular polygon circumscribing the sphere
    total_area = sphere_area + n * polygon_area
    
    return total_area
469 chars
17 lines

Here, we have imported the math module to use the pi, sin, and tan functions. We have defined a function surface_area_reg_polygon_circumscribed_sphere that takes the number of sides of the polygon (n) and the radius of the sphere (r) as inputs. First, we calculate the surface area of the sphere using the formula mentioned above. Then, we calculate the length of each side of the polygon using the formula 2 * r * sin(pi/n). Finally, we calculate the surface area of the polygon and the total surface area of the regular polygon circumscribed around the sphere using the formulae mentioned above.

We can call this function with suitable inputs to get the surface area of a regular polygon circumscribed around a sphere.

gistlibby LogSnag