# Basic Geometry Calculators (2D and 3D Objects)

• /
• Blog
• /
• Basic Geometry Calculators (2D and 3D Objects)

# Three Dimensional Objects

Calculate general parameters such as area, circumference, perimeter, and volume for basic geometric shapes.

## Cube Calculator

``` function calculateCube() { const calculationType = document.getElementById('cubeCalculationType').value; const sideLength = parseFloat(document.getElementById('cubeSideLength').value); let result = 0; let formula = ''; if (isNaN(sideLength) || sideLength <= 0) { alert('Please enter a valid side length.'); return; } if (calculationType === 'volume') { result = sideLength * sideLength * sideLength; formula = 's³'; } else if (calculationType === 'surfaceArea') { result = 6 * sideLength * sideLength; formula = '6s²'; } document.getElementById('cubeFormula').innerHTML = `Formula: \${formula}`; document.getElementById('cubeResult').innerHTML = `Result: \${result.toFixed(4)}`; } ```

## Cuboid Calculator

``` function calculateCuboid() { const calculationType = document.getElementById('cuboidCalculationType').value; const length = parseFloat(document.getElementById('cuboidLength').value); const width = parseFloat(document.getElementById('cuboidWidth').value); const height = parseFloat(document.getElementById('cuboidHeight').value); let result = 0; let formula = ''; if (isNaN(length) || length <= 0 || isNaN(width) || width <= 0 || isNaN(height) || height <= 0) { alert('Please enter valid dimensions.'); return; } switch(calculationType) { case 'volume': result = length * width * height; formula = 'lwh'; break; case 'surfaceArea': result = 2 * (length * width + length * height + width * height); formula = '2(lw + lh + wh)'; break; } document.getElementById('cuboidFormula').innerHTML = `Formula: \${formula}`; document.getElementById('cuboidResult').innerHTML = `Result: \${result.toFixed(4)}`; } ```

## Sphere Calculator

``` function calculateSphere() { const calculationType = document.getElementById('sphereCalculationType').value; const radius = parseFloat(document.getElementById('sphereRadius').value); const PI = Math.PI; let result = 0; let formula = ''; if (isNaN(radius) || radius <= 0) { alert('Please enter a valid radius.'); return; } if (calculationType === 'area') { result = 4 * PI * radius * radius; formula = '4πr²'; } else if (calculationType === 'volume') { result = (4/3) * PI * radius * radius * radius; formula = '4/3πr³'; } document.getElementById('sphereFormula').innerHTML = `Formula: \${formula}`; document.getElementById('sphereResult').innerHTML = `Result: \${result.toFixed(4)}`; } ```

## Cone Calculator

``` function calculateCone() { const calculationType = document.getElementById('coneCalculationType').value; const radius = parseFloat(document.getElementById('coneRadius').value); const height = parseFloat(document.getElementById('coneHeight').value); const PI = Math.PI; let result = 0; let formula = ''; if (isNaN(radius) || radius <= 0 || isNaN(height) || height <= 0) { alert('Please enter valid radius and height.'); return; } switch(calculationType) { case 'volume': result = (1/3) * PI * radius * radius * height; formula = '1/3πr²h'; break; case 'surfaceArea': let slantHeight = Math.sqrt(radius * radius + height * height); result = PI * radius * (radius + slantHeight); formula = 'πr(r + l)'; break; case 'baseArea': result = PI * radius * radius; formula = 'πr²'; break; case 'lateralSurfaceArea': let lateralSlantHeight = Math.sqrt(radius * radius + height * height); result = PI * radius * lateralSlantHeight; formula = 'πrl'; break; } document.getElementById('coneFormula').innerHTML = `Formula: \${formula}`; document.getElementById('coneResult').innerHTML = `Result: \${result.toFixed(4)}`; } ```

## Cylinder Calculator

``` function calculateCylinder() { const calculationType = document.getElementById('cylinderCalculationType').value; const radius = parseFloat(document.getElementById('cylinderRadius').value); const height = parseFloat(document.getElementById('cylinderHeight').value); const PI = Math.PI; let result = 0; let formula = ''; if (isNaN(radius) || radius <= 0 || isNaN(height) || height <= 0) { alert('Please enter valid radius and height.'); return; } switch(calculationType) { case 'volume': result = PI * radius * radius * height; formula = 'πr²h'; break; case 'lateralSurfaceArea': result = 2 * PI * radius * height; formula = '2πrh'; break; case 'topBottomArea': result = 2 * PI * radius * radius; formula = '2πr²'; break; case 'totalSurfaceArea': result = 2 * PI * radius * (height + radius); formula = '2πr(h + r)'; break; } document.getElementById('cylinderFormula').innerHTML = `Formula: \${formula}`; document.getElementById('cylinderResult').innerHTML = `Result: \${result.toFixed(4)}`; } ```

## Triangular Prism Calculator

``` function calculatePrism() { const calculationType = document.getElementById('prismCalculationType').value; const baseLength = parseFloat(document.getElementById('prismBase').value); const height = parseFloat(document.getElementById('prismHeight').value); const length = parseFloat(document.getElementById('prismLength').value); let result = 0; let formula = ''; if (isNaN(baseLength) || baseLength <= 0 || isNaN(height) || height <= 0 || isNaN(length) || length <= 0) { alert('Please enter valid dimensions.'); return; } const baseArea = 0.5 * baseLength * height; if (calculationType === 'volume') { result = baseArea * length; formula = '1/2 * base * height * length'; } else if (calculationType === 'surfaceArea') { const perimeter = baseLength * 3; // Assuming an equilateral triangle for simplicity result = (baseArea * 2) + (perimeter * length); formula = '2 * (1/2 * base * height) + (perimeter * length)'; } document.getElementById('prismFormula').innerHTML = `Formula: \${formula}`; document.getElementById('prismResult').innerHTML = `Result: \${result.toFixed(4)}`; } ```

## Square Pyramid Calculator

``` function calculatePyramid() { const calculationType = document.getElementById('pyramidCalculationType').value; const baseLength = parseFloat(document.getElementById('pyramidBase').value); const height = parseFloat(document.getElementById('pyramidHeight').value); let result = 0; let formula = ''; if (isNaN(baseLength) || baseLength <= 0 || isNaN(height) || height <= 0) { alert('Please enter valid dimensions.'); return; } if (calculationType === 'volume') { result = (baseLength * baseLength * height) / 3; formula = 'base² * height / 3'; } else if (calculationType === 'surfaceArea') { const slantHeight = Math.sqrt(height * height + (baseLength / 2) * (baseLength / 2)); const baseArea = baseLength * baseLength; const lateralArea = 4 * (baseLength * slantHeight / 2); result = baseArea + lateralArea; formula = 'base² + 4 * (base * slant height / 2)'; } document.getElementById('pyramidFormula').innerHTML = `Formula: \${formula}`; document.getElementById('pyramidResult').innerHTML = `Result: \${result.toFixed(4)}`; } ```

# Two Dimensional Objects

Calculate general parameters such as area, circumference, perimeter, and volume for basic geometric shapes.

## Square Calculator

``` function calculateSquare() { const calculationType = document.getElementById('squareCalculationType').value; const sideLength = parseFloat(document.getElementById('squareSideLength').value); let result = 0; let formula = ''; if (isNaN(sideLength) || sideLength <= 0) { alert('Please enter a valid side length.'); return; } if (calculationType === 'area') { result = sideLength * sideLength; formula = 'side²'; } else if (calculationType === 'perimeter') { result = 4 * sideLength; formula = '4 * side'; } document.getElementById('squareFormula').innerHTML = `Formula: \${formula}`; document.getElementById('squareResult').innerHTML = `Result: \${result.toFixed(4)}`; } ```

## Rectangle Calculator

``` function calculateRectangle() { const calculationType = document.getElementById('rectangleCalculationType').value; const length = parseFloat(document.getElementById('rectangleLength').value); const width = parseFloat(document.getElementById('rectangleWidth').value); let result = 0; let formula = ''; if (isNaN(length) || length <= 0 || isNaN(width) || width <= 0) { alert('Please enter valid dimensions.'); return; } if (calculationType === 'area') { result = length * width; formula = 'length * width'; } else if (calculationType === 'perimeter') { result = 2 * (length + width); formula = '2 * (length + width)'; } document.getElementById('rectangleFormula').innerHTML = `Formula: \${formula}`; document.getElementById('rectangleResult').innerHTML = `Result: \${result.toFixed(4)}`; } ```

## Circle Calculator

``` function calculateCircle() { const calculationType = document.getElementById('circleCalculationType').value; const radius = parseFloat(document.getElementById('circleRadius').value); const PI = Math.PI; let result = 0; let formula = ''; if (isNaN(radius) || radius <= 0) { alert('Please enter a valid radius.'); return; } if (calculationType === 'area') { result = PI * radius * radius; formula = 'πr²'; } else if (calculationType === 'circumference') { result = 2 * PI * radius; formula = '2πr'; } document.getElementById('circleFormula').innerHTML = `Formula: \${formula}`; document.getElementById('circleResult').innerHTML = `Result: \${result.toFixed(4)}`; } ```

## Right-Angled Triangle Calculator

``` function calculateTriangle() { const calculationType = document.getElementById('triangleCalculationType').value; const base = parseFloat(document.getElementById('triangleBase').value); const height = parseFloat(document.getElementById('triangleHeight').value); let result = 0; let formula = ''; if (isNaN(base) || base <= 0 || isNaN(height) || height <= 0) { alert('Please enter valid base and height.'); return; } if (calculationType === 'area') { result = 0.5 * base * height; formula = '1/2 * base * height'; } else if (calculationType === 'perimeter') { const hypotenuse = Math.sqrt(base * base + height * height); result = base + height + hypotenuse; formula = 'base + height + hypotenuse'; } document.getElementById('triangleFormula').innerHTML = `Formula: \${formula}`; document.getElementById('triangleResult').innerHTML = `Result: \${result.toFixed(4)}`; } ```

## Circle Sector Calculator

``` function calculateSector() { const calculationType = document.getElementById('sectorCalculationType').value; const radius = parseFloat(document.getElementById('sectorRadius').value); const angle = parseFloat(document.getElementById('sectorAngle').value); const PI = Math.PI; let result = 0; let formula = ''; if (isNaN(radius) || radius <= 0 || isNaN(angle) || angle <= 0) { alert('Please enter valid radius and angle.'); return; } const angleInRadians = (angle * PI) / 180; if (calculationType === 'area') { result = 0.5 * angleInRadians * radius * radius; formula = '1/2 * r² * θ (in radians)'; } else if (calculationType === 'arcLength') { result = angleInRadians * radius; formula = 'r * θ (in radians)'; } document.getElementById('sectorFormula').innerHTML = `Formula: \${formula}`; document.getElementById('sectorResult').innerHTML = `Result: \${result.toFixed(4)}`; } ```

Similar Posts:

February 18, 2024

## Mastering the Seven Basic Quality Tools (Accredited) (Online Training)

Mastering the Seven Basic Quality Tools (Accredited) (Online Training)

February 19, 2024

## CQIA Certified Quality Improvement Associate Practice Tests

CQIA Certified Quality Improvement Associate Practice Tests

February 18, 2024

## Root Cause Analysis and the 8D Problem Solving Bootcamp (Accredited) (Online Training)

Root Cause Analysis and the 8D Problem Solving Bootcamp (Accredited) (Online Training)

February 14, 2024

## Book SSGB

Book SSGB

December 28, 2021

## Benchmarking Quiz

Benchmarking Quiz

March 30, 2018

## 5 Key Philosophies Behind Lean

5 Key Philosophies Behind Lean

49 Courses on SALE!