To find the surface area of a triangular prism in TypeScript, you would need to use the formula:
Surface Area = (2 x Base Area) + (Perimeter of Base x Height of Prism)
Where Base Area is the area of the triangular base and Perimeter of Base is the perimeter of the triangular base. To calculate these values, we need to find the length of the sides of the triangle by using the Pythagorean theorem.
Here's the code example:
index.ts658 chars25 lines
In this code, we create a class TriangularPrism
with properties base
, height
, and prismHeight
. We then define a getter surfaceArea
that calculates the surface area of the triangular prism using the formula mentioned earlier.
To find the Base Area we calculate the area of the base of the triangular prism (1/2 bh). To find the Perimeter of Base we calculate the perimeter of the base of the triangular prism (3 x base) and then multiply that by the height of the prism to get the lateral surface area Finally we sum the area of the two bases 2*baseArea and the lateral surface area to get the final surface area.
We instantiate an object of TriangularPrism
with base of 4, height of 3, and prism height of 5. We then call the surfaceArea
getter to get the surface area of the prism which will output 62
.
gistlibby LogSnag