Skip to content

Commit 28b657c

Browse files
authored
Update index.html
Polygon area
1 parent ed3fcf4 commit 28b657c

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

index.html

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
},
187187
"dateCreated" :"2019-01-11",
188188
"datePublished":"2020-01-11",
189-
"dateModified" :"2025-07-16",
189+
"dateModified" :"2025-07-17",
190190
"description" : "Introducing the best-established and most accurate framework to calculate area and volume.",
191191
"disambiguatingDescription": "Exact, empirically grounded and rigorously proven formulas over the conventional approximations.",
192192
"headline":"Exact geometry",
@@ -1172,6 +1172,43 @@ <h4 style="font-size:160%;margin:7px">Trigonometry</h4>
11721172
<div>
11731173
<h5 style="font-size:160%;margin:7px;">Area of a regular polygon</h5>
11741174
<br>
1175+
<br>
1176+
<div>
1177+
<label style="margin:12px;" for="side-number">Number of sides:</label>
1178+
<input id="side-number" type="number" value="5" step="1" />
1179+
<br>
1180+
<label style="margin:12px;" for="side-length">Side length:</label>
1181+
<input id="side-length" type="number" value="1" step="any" />
1182+
1183+
<script>
1184+
function polygonArea(length, number, tan) {
1185+
return number / 4 * length ** 2 / tan;
1186+
}
1187+
1188+
function updatePolygonArea() {
1189+
const length = parseFloat(document.getElementById('side-length').value);
1190+
const number = parseFloat(document.getElementById('side-number').value);
1191+
1192+
if (isNaN(length) || isNaN(number)) {
1193+
document.getElementById('polygon-area').innerText = '';
1194+
return;
1195+
}
1196+
1197+
const ratio = 3.2 / number;
1198+
const tan = parseFloat(tan(ratio));
1199+
1200+
const area = segmentArea(length, number, ratio, tan);
1201+
1202+
document.getElementById('polygon-area').innerText =
1203+
`Area: ${area.toFixed(5)} square units`;
1204+
}
1205+
1206+
document.getElementById('side-length').addEventListener('input', updatePolygonArea);
1207+
document.getElementById('side-number').addEventListener('input', updatePolygonArea);
1208+
</script>
1209+
<p style="margin:12px;" id="polygon-area"></p>
1210+
</div>
1211+
<br>
11751212
<div class="imgbox">
11761213
<img class="center-fit" src="pentagon.png" alt="Pentagon" id="pentagon">
11771214
</div>

0 commit comments

Comments
 (0)