function updateFields() {
var shape = document.getElementById('shapeType').value;
document.getElementById('squareInputs').style.display = 'none';
document.getElementById('rectangleInputs').style.display = 'none';
document.getElementById('circleInputs').style.display = 'none';
document.getElementById('triangleInputs').style.display = 'none';
document.getElementById('perimeterResult').style.display = 'none';
if (shape === 'square') {
document.getElementById('squareInputs').style.display = 'block';
} else if (shape === 'rectangle') {
document.getElementById('rectangleInputs').style.display = 'block';
} else if (shape === 'circle') {
document.getElementById('circleInputs').style.display = 'block';
} else if (shape === 'triangle') {
document.getElementById('triangleInputs').style.display = 'block';
}
}
function calculatePerimeter() {
var shape = document.getElementById('shapeType').value;
var result = 0;
var isValid = true;
if (shape === 'square') {
var side = parseFloat(document.getElementById('sqSide').value);
if (isNaN(side) || side <= 0) { isValid = false; }
else { result = side * 4; }
}
else if (shape === 'rectangle') {
var length = parseFloat(document.getElementById('rectLength').value);
var width = parseFloat(document.getElementById('rectWidth').value);
if (isNaN(length) || isNaN(width) || length <= 0 || width <= 0) { isValid = false; }
else { result = 2 * (length + width); }
}
else if (shape === 'circle') {
var radius = parseFloat(document.getElementById('circRadius').value);
if (isNaN(radius) || radius <= 0) { isValid = false; }
else { result = 2 * Math.PI * radius; }
}
else if (shape === 'triangle') {
var a = parseFloat(document.getElementById('triSideA').value);
var b = parseFloat(document.getElementById('triSideB').value);
var c = parseFloat(document.getElementById('triSideC').value);
if (isNaN(a) || isNaN(b) || isNaN(c) || a <= 0 || b <= 0 || c <= 0) { isValid = false; }
else { result = a + b + c; }
}
if (isValid) {
document.getElementById('resultValue').innerText = result.toLocaleString(undefined, {minimumFractionDigits: 0, maximumFractionDigits: 2});
document.getElementById('perimeterResult').style.display = 'block';
} else {
alert("Please enter valid positive numbers for all required fields.");
}
}
How to Calculate a Perimeter: A Complete Guide
Understanding how to calculate a perimeter is a fundamental skill in geometry and real-world applications. Whether you are measuring a yard for fencing, framing a picture, or determining the distance around a park, the perimeter is the total distance around the boundary of a two-dimensional shape.
What is Perimeter?
In simple terms, the perimeter is the total length of the outline of a shape. Imagine placing a piece of string around the edge of an object and then laying that string flat against a ruler. The length of that string is the perimeter. For circular objects, this measurement is specifically called the circumference.
Perimeter Formulas for Common Shapes
Square: Since all four sides of a square are equal, you simply multiply one side by four.
Formula: P = 4 × side
Rectangle: A rectangle has two equal lengths and two equal widths. To find the perimeter, add the length and width together and multiply by two.
Formula: P = 2 × (length + width)
Circle (Circumference): To find the distance around a circle, you use the radius (the distance from the center to the edge) and the constant Pi (approximately 3.14159).
Formula: C = 2 × π × radius
Triangle: For any triangle, the perimeter is the sum of its three individual sides.
Formula: P = side A + side B + side C
Practical Examples
To better understand these calculations, let's look at a few realistic examples:
Example 1: Fencing a Rectangular Garden
If your garden is 20 meters long and 10 meters wide, the calculation would be:
P = 2 × (20 + 10) = 2 × 30 = 60 meters.
Example 2: Framing a Square Picture
If a square picture has a side length of 12 inches, the amount of wood needed for the frame is:
P = 4 × 12 = 48 inches.
Tips for Accurate Measurements
When calculating perimeter in real life, follow these best practices:
Consistency: Ensure all measurements are in the same units (e.g., all inches or all centimeters) before adding them together.
Include Overlap: If you are buying material like trim or molding, always add 10% to your final perimeter calculation to account for waste or corners.
Double-Check Sides: For irregular shapes (polygons), make sure you have measured every single straight edge before summing them up.
Use our free Perimeter Calculator above to quickly find the dimensions for your next project, whether it's for school, home renovation, or DIY crafts!