find the surface area of a regular polygon circumscribed around a triangular prism in ruby

To find the surface area of a regular polygon circumscribed around a triangular prism in Ruby, we need to follow these steps:

  1. Find the side length (s) of the regular polygon by dividing its perimeter by the number of sides.
  2. Use the side length (s) and the height (h) of the triangular prism to find the area of one lateral face of the prism.
  3. Multiply the area of one lateral face by the number of sides of the polygon to get the total lateral surface area of the prism.
  4. Add the area of the two triangular bases of the prism to the total lateral surface area to get the total surface area of the polygon circumscribed around the prism.

Here's the Ruby code for this:

main.rb
# function to find the surface area of a regular polygon circumscribed around a triangular prism
def surface_area_of_polygon_circumscribed_around_triangular_prism(sides, perimeter, height)
    side_length = perimeter / sides.to_f
    lateral_area = side_length * height
    lateral_surface_area = lateral_area * sides
    base_area = (side_length * height) / 2
    total_surface_area = lateral_surface_area + (2 * base_area)
    return total_surface_area
end

# example usage
sides = 6
perimeter = 36
height = 10
puts "Surface area of the regular polygon circumscribed around the triangular prism = #{surface_area_of_polygon_circumscribed_around_triangular_prism(sides, perimeter, height)}"
691 chars
16 lines

In this code, we define a function surface_area_of_polygon_circumscribed_around_triangular_prism that takes three arguments - sides, perimeter, and height - and returns the surface area of the regular polygon circumscribed around the triangular prism.

In the example usage, we pass in the values of sides, perimeter, and height and print the result using string interpolation.

gistlibby LogSnag