How to use Separate Variables for Triangle and Prism In Javascript

In this approach, we are using separate variables to calculate the volumes of the triangular pyramid and triangular prism, then adding them to determine the total volume of the rectangular right wedge.

Example: The below example uses Separate Variables for Triangle and Prism to find the volume of the wedge.

JavaScript
let a = 2,
  b = 5,
  e = 5,
  h = 6;
let Va = (1 / 3) * ((1 / 2) * (b * h * (e - a)));
let Vb = (1 / 2) * (b * h * a);
let res = Va + Vb;
console.log(`Volume = ${res.toFixed(1)}`);

Output
Volume = 45.0

Time Complexity: O(1)

Space Complexity: O(1)


JavaScript Program to Find Volume of Right Wedge

A wedge is a three-dimensional object with two triangular faces and one rectangular face.

Examples: 

Input: a = 2, b = 5, e = 5, h = 6 
Output: Volume = 45.0

Input: a = 5, b = 4, e = 4, h = 6 
Output: Volume = 56.0 

Similar Reads

Approach:

...

Using Direct Calculation

In this approach, we are using a direct calculation based on the formula for a rectangular right wedge to find its volume without intermediary calculations of separate components....

Using Separate Variables for Triangle and Prism

In this approach, we are using separate variables to calculate the volumes of the triangular pyramid and triangular prism, then adding them to determine the total volume of the rectangular right wedge....