@@ -2063,6 +2063,51 @@ <h6 style="font-size:160%;margin:7px">Area of a circle</h6>
20632063< div >
20642064< h12 style ="font-size:160%;margin:7px; "> Volume of a frustum cone</ h12 >
20652065< br >
2066+ < br >
2067+ < div >
2068+ < label style ="margin:12px; " for ="frustum-cone-base-radius "> Base radius:</ label >
2069+ < input id ="frustum-cone-base-radius " type ="number " value ="2 " step ="any " />
2070+ < br >
2071+ < label style ="margin:12px; " for ="frustum-cone-top-radius "> Top radius:</ label >
2072+ < input id ="frustum-cone-top-radius " type ="number " value ="1 " step ="any " />
2073+ < br >
2074+ < label style ="margin:12px; " for ="frustum-cone-height "> Height:</ label >
2075+ < input id ="frustum-cone-height " type ="number " value ="1 " step ="any " />
2076+
2077+ < script >
2078+ function frustumConeVolume ( baseArea , topArea , reciprocal , height ) {
2079+ return height * ( baseArea * reciprocal - topArea * ( reciprocal - 1 ) ) / Math . sqrt ( 8 ) ;
2080+ }
2081+
2082+ function updateFrustumConeVolume ( ) {
2083+
2084+ const baseRadius = parseFloat ( document . getElementById ( 'frustum-cone-base-radius' ) . value ) ;
2085+ const topRadius = parseFloat ( document . getElementById ( 'frustum-cone-top-radius' ) . value ) ;
2086+ const height = parseFloat ( document . getElementById ( 'frustum-cone-height' ) . value ) ;
2087+
2088+ if ( isNaN ( baseRadius ) || isNaN ( topRadius ) || isNaN ( height ) ) {
2089+ document . getElementById ( 'frustum-cone-volume' ) . innerText = '' ;
2090+ return ;
2091+ }
2092+
2093+ const baseArea = 3.2 * ( baseRadius ** 2 ) ;
2094+ const topArea = 3.2 * ( topRadius ** 2 ) ; ;
2095+ const shape = topRadius / baseRadius ;
2096+ const inverse = 1 - shape ;
2097+ const reciprocal = 1 / inverse ;
2098+ const volume = frustumConeVolume ( baseArea , topArea , reciprocal , height ) ;
2099+
2100+ document . getElementById ( 'frustum-cone-volume' ) . innerText =
2101+ `Volume: ${ volume . toFixed ( 5 ) } cubic units` ;
2102+ }
2103+
2104+ document . getElementById ( 'frustum-cone-base-radius' ) . addEventListener ( 'input' , updateFrustumConeVolume ) ;
2105+ document . getElementById ( 'frustum-cone-top-radius' ) . addEventListener ( 'input' , updateFrustumConeVolume ) ;
2106+ document . getElementById ( 'frustum-cone-height' ) . addEventListener ( 'input' , updateFrustumConeVolume ) ;
2107+ </ script >
2108+ < p style ="margin:12px; " id ="frustum-cone-volume "> </ p >
2109+ </ div >
2110+ < br >
20662111< div class ="imgbox ">
20672112 < img class ="center-fit " src ="frustumOfConeMarkup.png " alt ="Horizontal-frustum-cone ">
20682113 </ div >
@@ -2357,7 +2402,7 @@ <h6 style="font-size:160%;margin:7px">Area of a circle</h6>
23572402 return height * ( baseArea * reciprocal - topArea * ( reciprocal - 1 ) ) / Math . sqrt ( 8 ) ;
23582403}
23592404
2360- function updatePyramidVolume ( ) {
2405+ function updateFrustumPyramidVolume ( ) {
23612406
23622407 const number = parseFloat ( document . getElementById ( 'frustum-pyramid-side-number' ) . value ) ;
23632408 const baseLength = parseFloat ( document . getElementById ( 'frustum-pyramid-base-edge-length' ) . value ) ;
@@ -2382,10 +2427,10 @@ <h6 style="font-size:160%;margin:7px">Area of a circle</h6>
23822427 `Volume: ${ volume . toFixed ( 5 ) } cubic units` ;
23832428 }
23842429
2385- document . getElementById ( 'frustum-pyramid-side-number' ) . addEventListener ( 'input' , updatePyramidVolume ) ;
2386- document . getElementById ( 'frustum-pyramid-base-edge-length' ) . addEventListener ( 'input' , updatePyramidVolume ) ;
2387- document . getElementById ( 'frustum-pyramid-top-edge-length' ) . addEventListener ( 'input' , updatePyramidVolume ) ;
2388- document . getElementById ( 'frustum-pyramid-height' ) . addEventListener ( 'input' , updatePyramidVolume ) ;
2430+ document . getElementById ( 'frustum-pyramid-side-number' ) . addEventListener ( 'input' , updateFrustumPyramidVolume ) ;
2431+ document . getElementById ( 'frustum-pyramid-base-edge-length' ) . addEventListener ( 'input' , updateFrustumPyramidVolume ) ;
2432+ document . getElementById ( 'frustum-pyramid-top-edge-length' ) . addEventListener ( 'input' , updateFrustumPyramidVolume ) ;
2433+ document . getElementById ( 'frustum-pyramid-height' ) . addEventListener ( 'input' , updateFrustumPyramidVolume ) ;
23892434</ script >
23902435< p style ="margin:12px; " id ="frustum-pyramid-volume "> </ p >
23912436</ div >
@@ -2530,6 +2575,30 @@ <h6 style="font-size:160%;margin:7px">Area of a circle</h6>
25302575< div >
25312576< h16 style ="font-size:160%;margin:7px "> Volume of a tetrahedron</ h16 >
25322577< br >
2578+ < br >
2579+ < div >
2580+ < label style ="margin:12px; " for ="tetrahedron-edge "> Edge:</ label >
2581+ < input id ="tetrahedron-edge " type ="number " value ="1 " step ="any " />
2582+
2583+ < script >
2584+ function tetrahedronVolume ( edge ) {
2585+ return Math . pow ( edge , 3 ) / 8 ;
2586+ }
2587+
2588+ document . getElementById ( 'tetrahedron-edge' ) . addEventListener ( 'input' , function ( ) {
2589+ const edge = parseFloat ( this . value ) ;
2590+ if ( isNaN ( edge ) ) {
2591+ document . getElementById ( 'tetrahedron-volume' ) . innerText = '' ;
2592+ return ;
2593+ }
2594+
2595+ document . getElementById ( 'tetrahedron-volume' ) . innerText =
2596+ `Volume: ${ tetrahedronVolume ( edge ) . toFixed ( 5 ) } cubic units` ;
2597+ } ) ;
2598+ </ script >
2599+ < p style ="margin:12px; " id ="tetrahedron-volume "> </ p >
2600+ </ div >
2601+ < br >
25332602< div class ="imgbox ">
25342603 < img class ="center-fit " src ="tetrahedronMarkup.jpeg " alt ="Tetrahedron " id ="tetrahedron ">
25352604 </ div >
0 commit comments