Volume is a fundamental concept in geometry and physics, representing the amount of three-dimensional space occupied by an object or a substance. It's typically measured in cubic units, such as cubic meters (m³), cubic centimeters (cm³), or cubic feet (ft³). Different shapes have specific formulas to calculate their volume, based on their dimensions.
Common Geometric Shapes and Their Volume Formulas:
Our calculator supports the following shapes:
Cube
A cube is a special type of cuboid where all six faces are squares, and all edges are of equal length.
Volume = side³
Where 'side' is the length of one edge of the cube.
Cuboid (Rectangular Prism)
A cuboid is a three-dimensional shape with six rectangular faces.
Volume = length × width × height
Where 'length', 'width', and 'height' are the dimensions of the cuboid.
Cylinder
A cylinder is a three-dimensional solid that has two parallel circular bases connected by a curved surface.
Volume = π × radius² × height
Where 'π' (pi) is approximately 3.14159, 'radius' is the radius of the circular base, and 'height' is the perpendicular distance between the bases.
Sphere
A sphere is a perfectly round geometrical object in three-dimensional space.
Volume = (4/3) × π × radius³
Where 'π' is approximately 3.14159 and 'radius' is the distance from the center of the sphere to any point on its surface.
Cone
A cone is a three-dimensional geometric shape that tapers smoothly from a flat base (usually circular) to a point called the apex or vertex.
Volume = (1/3) × π × radius² × height
Where 'π' is approximately 3.14159, 'radius' is the radius of the circular base, and 'height' is the perpendicular distance from the base to the apex.
Pyramid (Square Base)
A pyramid is a polyhedron formed by connecting a polygonal base and a point, called the apex.
Volume = (1/3) × base_area × height
For a square base: Volume = (1/3) × side² × height
Where 'side' is the length of one side of the square base, and 'height' is the perpendicular distance from the base to the apex.
Use Cases for Volume Calculation:
Engineering & Construction: Calculating the amount of material needed (concrete, steel, liquids) for structures, reservoirs, or pipelines.
Logistics & Shipping: Determining how much can fit into containers, trucks, or warehouses to optimize space and cost.
Science & Chemistry: Measuring the volume of liquids or gases in experiments, determining density.
Manufacturing: Calculating the capacity of tanks, vessels, or molds for product production.
Everyday Life: Estimating the amount of soil for a garden, capacity of a swimming pool, or ingredients for cooking.
function updateInputs() {
var shape = document.getElementById("shape").value;
var inputHtml = ";
switch (shape) {
case 'cube':
inputHtml = '
' +
'' +
" +
'
';
break;
case 'cuboid':
inputHtml = '
' +
'' +
" +
'
' +
'
' +
'' +
" +
'
' +
'
' +
'' +
" +
'
';
break;
case 'cylinder':
inputHtml = '
' +
'' +
" +
'
' +
'
' +
'' +
" +
'
';
break;
case 'sphere':
inputHtml = '
' +
'' +
" +
'
';
break;
case 'cone':
inputHtml = '
' +
'' +
" +
'
' +
'
' +
'' +
" +
'
';
break;
case 'pyramid':
inputHtml = '
' +
'' +
" +
'
' +
'
' +
'' +
" +
'
';
break;
}
document.getElementById("shape-specific-inputs").innerHTML = inputHtml;
}
function calculateVolume() {
var shape = document.getElementById("shape").value;
var volume = 0;
var resultUnit = 'cubic units';
var inputValuesValid = true;
try {
switch (shape) {
case 'cube':
var side = parseFloat(document.getElementById("sideCube").value);
if (isNaN(side) || side <= 0) { inputValuesValid = false; } else { volume = Math.pow(side, 3); }
break;
case 'cuboid':
var length = parseFloat(document.getElementById("lengthCuboid").value);
var width = parseFloat(document.getElementById("widthCuboid").value);
var height = parseFloat(document.getElementById("heightCuboid").value);
if (isNaN(length) || isNaN(width) || isNaN(height) || length <= 0 || width <= 0 || height <= 0) { inputValuesValid = false; } else { volume = length * width * height; }
break;
case 'cylinder':
var radius = parseFloat(document.getElementById("radiusCylinder").value);
var height = parseFloat(document.getElementById("heightCylinder").value);
if (isNaN(radius) || isNaN(height) || radius <= 0 || height <= 0) { inputValuesValid = false; } else { volume = Math.PI * Math.pow(radius, 2) * height; }
break;
case 'sphere':
var radius = parseFloat(document.getElementById("radiusSphere").value);
if (isNaN(radius) || radius <= 0) { inputValuesValid = false; } else { volume = (4/3) * Math.PI * Math.pow(radius, 3); }
break;
case 'cone':
var radius = parseFloat(document.getElementById("radiusCone").value);
var height = parseFloat(document.getElementById("heightCone").value);
if (isNaN(radius) || isNaN(height) || radius <= 0 || height <= 0) { inputValuesValid = false; } else { volume = (1/3) * Math.PI * Math.pow(radius, 2) * height; }
break;
case 'pyramid':
var baseSide = parseFloat(document.getElementById("baseSidePyramid").value);
var height = parseFloat(document.getElementById("heightPyramid").value);
if (isNaN(baseSide) || isNaN(height) || baseSide <= 0 || height <= 0) { inputValuesValid = false; } else { volume = (1/3) * Math.pow(baseSide, 2) * height; }
break;
}
if (inputValuesValid) {
document.getElementById("result-value").textContent = volume.toFixed(4); // Display with 4 decimal places
document.getElementById("result-unit").textContent = resultUnit;
} else {
document.getElementById("result-value").textContent = "Invalid Input";
document.getElementById("result-unit").textContent = "";
}
} catch (error) {
document.getElementById("result-value").textContent = "Error";
document.getElementById("result-unit").textContent = "";
console.error("Calculation error:", error);
}
}
// Initialize inputs when the page loads
window.onload = updateInputs;