Square
Rectangle
Circle
Triangle (Right)
Sphere
Cube
Cylinder
Cone
Please select a shape and enter its dimensions.
Understanding Geometric Calculations
Geometry is a fundamental branch of mathematics concerned with shapes, sizes, positions of figures, and properties of space. Geometric calculations are essential in various fields, including architecture, engineering, design, physics, and everyday life. This calculator helps you quickly determine key properties like area, perimeter, volume, and surface area for common geometric shapes.
Common Shapes and Their Formulas:
Square: A quadrilateral with four equal sides and four right angles.
Area = side * side (s²)
Perimeter = 4 * side (4s)
Rectangle: A quadrilateral with four right angles and opposite sides equal.
Area = length * width (l * w)
Perimeter = 2 * (length + width) (2(l + w))
Circle: A set of points equidistant from a central point.
Area = π * radius² (πr²)
Circumference = 2 * π * radius (2πr)
Note: π (Pi) is approximately 3.14159.
Triangle (Right): A triangle with one angle measuring 90 degrees. For simplicity, we'll calculate area based on base and height.
Area = 0.5 * base * height (0.5 * b * h)
Perimeter = side1 + side2 + side3 (requires lengths of all sides)
Sphere: A perfectly round geometrical object in three-dimensional space.
Volume = (4/3) * π * radius³ ((4/3)πr³)
Surface Area = 4 * π * radius² (4πr²)
Cube: A three-dimensional solid object bounded by six square faces.
Volume = side³ (s³)
Surface Area = 6 * side² (6s²)
Cylinder: A three-dimensional solid that holds two parallel bases joined by an ovular surface.
Cone: A three-dimensional geometric shape that tapers smoothly from a flat base (frequently, though not necessarily, circular) to a point called the apex or vertex.
Whether you're a student learning about geometric principles, a homeowner planning renovations, a designer visualizing spaces, or an engineer calculating material requirements, having a reliable geometry calculator is invaluable. It simplifies complex calculations, reduces the chance of errors, and saves significant time. For example, calculating the area of a room helps determine how much carpet or paint is needed, while calculating the volume of a spherical tank is crucial in fluid dynamics and storage applications.
function updateInputs() {
var shapeType = document.getElementById("shapeType").value;
var inputFieldsDiv = document.getElementById("inputFields");
var html = ";
switch (shapeType) {
case 'square':
html = `
`;
break;
case 'rectangle':
html = `
`;
break;
case 'circle':
html = `
`;
break;
case 'triangle':
html = `
`;
break;
case 'sphere':
html = `
`;
break;
case 'cube':
html = `
`;
break;
case 'cylinder':
html = `
`;
break;
case 'cone':
html = `
`;
break;
}
inputFieldsDiv.innerHTML = html;
}
function calculateGeometry() {
var shapeType = document.getElementById("shapeType").value;
var resultDiv = document.getElementById("result");
var area = null;
var perimeter = null;
var volume = null;
var surfaceArea = null;
var pi = Math.PI;
var calculationOutput = "";
try {
switch (shapeType) {
case 'square':
var side = parseFloat(document.getElementById("sideLength").value);
if (isNaN(side) || side <= 0) throw new Error("Please enter a valid positive side length.");
area = side * side;
perimeter = 4 * side;
calculationOutput = `Area: ${area.toFixed(2)}Perimeter: ${perimeter.toFixed(2)}`;
break;
case 'rectangle':
var length = parseFloat(document.getElementById("rectLength").value);
var width = parseFloat(document.getElementById("rectWidth").value);
if (isNaN(length) || length <= 0 || isNaN(width) || width <= 0) throw new Error("Please enter valid positive length and width.");
area = length * width;
perimeter = 2 * (length + width);
calculationOutput = `Area: ${area.toFixed(2)}Perimeter: ${perimeter.toFixed(2)}`;
break;
case 'circle':
var radius = parseFloat(document.getElementById("radius").value);
if (isNaN(radius) || radius <= 0) throw new Error("Please enter a valid positive radius.");
area = pi * radius * radius;
perimeter = 2 * pi * radius; // Circumference
calculationOutput = `Area: ${area.toFixed(2)}Circumference: ${perimeter.toFixed(2)}`;
break;
case 'triangle':
var base = parseFloat(document.getElementById("base").value);
var height = parseFloat(document.getElementById("height").value);
if (isNaN(base) || base <= 0 || isNaN(height) || height <= 0) throw new Error("Please enter valid positive base and height.");
area = 0.5 * base * height;
// Perimeter for a general triangle is complex without knowing all sides.
// For a right triangle, if base and height are legs, hypotenuse is sqrt(base^2 + height^2)
var hypotenuse = Math.sqrt(base * base + height * height);
perimeter = base + height + hypotenuse;
calculationOutput = `Area: ${area.toFixed(2)}Perimeter (Right Triangle): ${perimeter.toFixed(2)}`;
break;
case 'sphere':
var radius = parseFloat(document.getElementById("sphereRadius").value);
if (isNaN(radius) || radius <= 0) throw new Error("Please enter a valid positive radius.");
volume = (4/3) * pi * radius * radius * radius;
surfaceArea = 4 * pi * radius * radius;
calculationOutput = `Volume: ${volume.toFixed(2)}Surface Area: ${surfaceArea.toFixed(2)}`;
break;
case 'cube':
var side = parseFloat(document.getElementById("cubeSide").value);
if (isNaN(side) || side <= 0) throw new Error("Please enter a valid positive side length.");
volume = side * side * side;
surfaceArea = 6 * side * side;
calculationOutput = `Volume: ${volume.toFixed(2)}Surface Area: ${surfaceArea.toFixed(2)}`;
break;
case 'cylinder':
var radius = parseFloat(document.getElementById("cylRadius").value);
var height = parseFloat(document.getElementById("cylHeight").value);
if (isNaN(radius) || radius <= 0 || isNaN(height) || height <= 0) throw new Error("Please enter valid positive radius and height.");
volume = pi * radius * radius * height;
surfaceArea = (2 * pi * radius * height) + (2 * pi * radius * radius);
calculationOutput = `Volume: ${volume.toFixed(2)}Surface Area: ${surfaceArea.toFixed(2)}`;
break;
case 'cone':
var radius = parseFloat(document.getElementById("coneRadius").value);
var height = parseFloat(document.getElementById("coneHeight").value);
if (isNaN(radius) || radius <= 0 || isNaN(height) || height <= 0) throw new Error("Please enter valid positive radius and height.");
volume = (1/3) * pi * radius * radius * height;
var slantHeight = Math.sqrt(height * height + radius * radius);
surfaceArea = pi * radius * (radius + slantHeight);
calculationOutput = `Volume: ${volume.toFixed(2)}Surface Area: ${surfaceArea.toFixed(2)}`;
break;
default:
throw new Error("Invalid shape selected.");
}
resultDiv.innerHTML = calculationOutput;
} catch (e) {
resultDiv.innerHTML = `Error: ${e.message}`;
resultDiv.style.backgroundColor = "#dc3545"; // Red for error
setTimeout(function() {
resultDiv.style.backgroundColor = "var(–success-green)"; // Revert to green
resultDiv.innerHTML = "Please select a shape and enter its dimensions.";
}, 3000);
}
}
// Initialize inputs for the default shape (Square) on load
document.addEventListener("DOMContentLoaded", updateInputs);