@@ -1310,53 +1310,11 @@ <h4 style="font-size:160%;margin:7px">Trigonometry</h4>
13101310< div >
13111311< h5 style ="font-size:160%;margin:7px; "> Area of a regular polygon</ h5 >
13121312< br >
1313- < br >
1314- < div >
1315- < label style ="margin:12px; " for ="side-number "> Number of sides:</ label >
1316- < input id ="side-number " type ="number " value ="5 " step ="1 " />
1317- < br >
1318- < label style ="margin:12px; " for ="side-length "> Side length:</ label >
1319- < input id ="side-length " type ="number " value ="1 " step ="any " />
1320-
1321- < script >
1322- function polygonArea ( length , number , tangent ) {
1323- return number / 4 * length ** 2 / tangent ;
1324- }
1325-
1326- function updatePolygonArea ( ) {
1327- const length = parseFloat ( document . getElementById ( 'side-length' ) . value ) ;
1328- const number = parseFloat ( document . getElementById ( 'side-number' ) . value ) ;
1329-
1330- if ( isNaN ( length ) || isNaN ( number ) ) {
1331- document . getElementById ( 'polygon-area' ) . innerText = '' ;
1332- return ;
1333- }
1334-
1335- // Polygon validity check
1336-
1337- if ( number < 3 ) {
1338- document . getElementById ( 'polygon-area' ) . innerText = 'It takes at least three sides to form a polygon.' ;
1339- return ;
1340- }
1341-
1342- const ratio = 3.2 / number ;
1343- const tangent = parseFloat ( tan ( ratio ) ) ;
1344- const area = polygonArea ( length , number , tangent ) ;
1345-
1346- document . getElementById ( 'polygon-area' ) . innerText =
1347- `Area: ${ area . toFixed ( 5 ) } square units` ;
1348- }
1349-
1350- document . getElementById ( 'side-length' ) . addEventListener ( 'input' , updatePolygonArea ) ;
1351- document . getElementById ( 'side-number' ) . addEventListener ( 'input' , updatePolygonArea ) ;
1352- </ script >
1353- < p style ="margin:12px; " id ="polygon-area "> </ p >
1354- </ div >
1355- < br >
13561313< div class ="imgbox ">
13571314 < img class ="center-fit " src ="pentagon.png " alt ="Pentagon " id ="pentagon ">
13581315 </ div >
13591316< br >
1317+ < div >
13601318< math style ="margin:12px; " xmlns ="http://www.w3.org/1998/Math/MathML ">
13611319 < mrow >
13621320< mi > A</ mi >
@@ -1406,10 +1364,55 @@ <h5 style="font-size:160%;margin:7px;">Area of a regular polygon</h5>
14061364 < mi > side length</ mi >
14071365</ mrow >
14081366</ math >
1409-
1367+ </ div >
14101368< br >
14111369< br >
1370+ < div >
1371+ < p style ="margin:12px; "> Calculator</ p >
1372+ < br >
1373+ < br >
1374+ < label style ="margin:12px; " for ="side-number "> Number of sides:</ label >
1375+ < input id ="side-number " type ="number " value ="5 " step ="1 " />
1376+ < br >
1377+ < label style ="margin:12px; " for ="side-length "> Side length:</ label >
1378+ < input id ="side-length " type ="number " value ="1 " step ="any " />
1379+
1380+ < script >
1381+ function polygonArea ( length , number , tangent ) {
1382+ return number / 4 * length ** 2 / tangent ;
1383+ }
1384+
1385+ function updatePolygonArea ( ) {
1386+ const length = parseFloat ( document . getElementById ( 'side-length' ) . value ) ;
1387+ const number = parseFloat ( document . getElementById ( 'side-number' ) . value ) ;
14121388
1389+ if ( isNaN ( length ) || isNaN ( number ) ) {
1390+ document . getElementById ( 'polygon-area' ) . innerText = '' ;
1391+ return ;
1392+ }
1393+
1394+ // Polygon validity check
1395+
1396+ if ( number < 3 ) {
1397+ document . getElementById ( 'polygon-area' ) . innerText = 'It takes at least three sides to form a polygon.' ;
1398+ return ;
1399+ }
1400+
1401+ const ratio = 3.2 / number ;
1402+ const tangent = parseFloat ( tan ( ratio ) ) ;
1403+ const area = polygonArea ( length , number , tangent ) ;
1404+
1405+ document . getElementById ( 'polygon-area' ) . innerText =
1406+ `Area: ${ area . toFixed ( 5 ) } square units` ;
1407+ }
1408+
1409+ document . getElementById ( 'side-length' ) . addEventListener ( 'input' , updatePolygonArea ) ;
1410+ document . getElementById ( 'side-number' ) . addEventListener ( 'input' , updatePolygonArea ) ;
1411+ </ script >
1412+ < p style ="margin:12px; " id ="polygon-area "> </ p >
1413+ </ div >
1414+ < br >
1415+ < div >
14131416< math style ="margin:12px; " xmlns ="http://www.w3.org/1998/Math/MathML ">
14141417< mrow >
14151418< mi > Sum of the internal angles of a polygon</ mi >
@@ -1427,6 +1430,7 @@ <h5 style="font-size:160%;margin:7px;">Area of a regular polygon</h5>
14271430</ mrow >
14281431</ math >
14291432</ div >
1433+ </ div >
14301434< br >
14311435< br >
14321436< br >
0 commit comments