find the surface area of a regular polygon inscribed in a triangular prism in csharp

To find the surface area of a regular polygon inscribed in a triangular prism, we can break it down into two parts: the surface area of the base polygon and the surface area of the lateral faces.

The surface area of a regular polygon can be calculated using the formula:

main.cs
double surfaceAreaOfBasePolygon(double sideLength, int numSides)
{
    double apothem = sideLength / (2 * Math.Tan(Math.PI / numSides));
    double perimeter = sideLength * numSides;
    double area = (perimeter * apothem) / 2;
    
    return area;
}
252 chars
9 lines

Where sideLength is the length of one side of the polygon, and numSides is the number of sides in the polygon.

The surface area of the lateral faces can be found by calculating the perimeter of the polygon (sideLength * numSides) and multiplying it by the height of the prism. In this case, the height of the prism is equal to the apothem of the polygon.

main.cs
double surfaceAreaOfLateralFaces(double sideLength, int numSides, double height)
{
    double perimeter = sideLength * numSides;
    double area = perimeter * height;
    
    return area;
}
191 chars
8 lines

To find the total surface area of the regular polygon inscribed in the triangular prism, we add the surface area of the base polygon and the surface area of the lateral faces.

main.cs
double surfaceAreaOfRegularPolygonInTriangularPrism(double sideLength, int numSides, double height)
{
    double baseArea = surfaceAreaOfBasePolygon(sideLength, numSides);
    double lateralArea = surfaceAreaOfLateralFaces(sideLength, numSides, height);
    
    return baseArea + lateralArea;
}
296 chars
8 lines

gistlibby LogSnag