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

To find the surface area of a regular polygon circumscribed around a cone, we can use the following formula:

Surface area = area of polygon + area of cone base

To compute the area of the polygon, we need to know the number of sides n, the length of each side s, and the apothem a (the distance from the center of the polygon to the midpoint of a side).

To compute the area of the cone base, we need to know the radius r of the circumscribing circle of the polygon.

Here's the Python code:

main.py
import math

def surface_area_of_polygon_circumscribed_around_cone(n, r, s):
    a = r * math.sin(math.pi / n)
    polygon_area = 0.5 * n * s * a
    cone_base_area = math.pi * r ** 2
    surface_area = polygon_area + cone_base_area
    return surface_area
257 chars
9 lines

Here's an example usage of the function:

main.py
>>> surface_area_of_polygon_circumscribed_around_cone(6, 5, 3)
147.21110255092798
82 chars
3 lines

This means that a regular hexagon with side length 3 and a circumscribing circle of radius 5 around a cone has a surface area of approximately 147.21.

gistlibby LogSnag