To find the surface area of a regular polygon inscribed in a triangular prism, we need to calculate the area of each face of the triangular prism and subtract the area of the bases.
Here's the code to find the surface area of a regular polygon inscribed in a triangular prism:
main.rs773 chars17 lines
In this code, we first define the number of sides of the regular polygon n
, the radius of the inscribed circle r
, the length of one side of the polygon a
and the height of the triangular prism h
.
Then, we calculate the area of the regular polygon using the formula n * a * r / 2
where n
is the number of sides of the polygon, a
is the length of one side of the polygon and r
is the radius of the circle inscribed in the polygon.
Next, we calculate the area of the sides of the triangular prism using the formula n * a * h
, where n
is the number of sides of the polygon, a
is the length of one side of the polygon and h
is the height of the triangular prism.
Then, we calculate the area of the triangular bases of the prism using the formula 1.5 * n * r^2 * sin(2*PI/n)
, where n
is the number of sides of the polygon, r
is the radius of the circle inscribed in the polygon and PI
is the constant value of pi in Rust.
Finally, we calculate the total surface area of the triangular prism with the inscribed regular polygon by adding the area of the sides of the prism, twice the area of one base of the prism and the area of the regular polygon inscribed, and then subtracting the area of the regular polygon inscribed.
The result will be printed to the console using the println!
macro.
gistlibby LogSnag