@@ -3269,26 +3269,55 @@ <h3 itemprop="name" style="margin:7px">Area of a Circle Segment</h3>
32693269</ div >
32703270< br >
32713271< br >
3272- < div style ="margin:12px " id ="circle-segment_area_calculator ">
3273- < label for ="segment-length "> Length:</ label >
3274- < input id ="segment-length " type ="number " value ="2 " step ="any ">
3275- < br >
32763272< label for ="segment-height "> Height:</ label >
32773273< input id ="segment-height " type ="number " value ="1 " step ="any ">
3274+ < br >
3275+ < div style ="margin:12px " id ="circle-segment_area_calculator ">
3276+ < label for ="segment-length "> Chird Length:</ label >
3277+ < input id ="chord-length " type ="number " value ="2 " step ="any ">
3278+ < br >
3279+ < label for ="segment-height "> Circle Radius:</ label >
3280+ < input id ="parent-radius " type ="number " value ="1 " step ="any ">
32783281< script >
32793282 function segmentArea ( length , height , angle , radius ) {
3280- return 2 * angle * radius ** 2 - ( radius - height ) * length / 2 ;
3283+ return angle * radius ** 2 - ( radius - height ) * length / 2 ;
32813284 }
32823285
32833286function updateSegmentArea ( ) {
3284- const length = parseFloat ( document . getElementById ( 'segment -length' ) . value ) ;
3287+ const length = parseFloat ( document . getElementById ( 'chord -length' ) . value ) ;
32853288 const height = parseFloat ( document . getElementById ( 'segment-height' ) . value ) ;
3289+ const radius = parseFloat ( document . getElementById ( 'parent-radius' ) . value ) ;
32863290
3287- if ( isNaN ( length ) || isNaN ( height ) || height === 0 || length === 0 ) {
3291+ if ( isNaN ( height ) || isNaN ( length ) || isNaN ( radius ) || height === 0 || length === 0 || radius === 0 ) {
32883292 document . getElementById ( 'segment-area' ) . innerText = '' ;
32893293 return ;
3290- }
3294+ }
3295+
3296+ // If height and parent radius is known
3297+
3298+ else if ( ! isNaN ( height ) || ! isNaN ( radius ) || height > 0 || radius > 0 ) {
3299+
3300+ const ratio = ( radius - height ) / radius ;
3301+
3302+ // Segment validity check
3303+
32913304
3305+ if ( ratio > 1 ) {
3306+ document . getElementById ( 'segment-area' ) . innerText = 'This ratio is out of range' ;
3307+ return ;
3308+ }
3309+
3310+ const angle = parseFloat ( Acos ( ratio ) ) ;
3311+ const length = parseFloat ( 2 * sin ( angle ) * radius ) ;
3312+
3313+ document . getElementById ( 'segment-area' ) . innerText =
3314+ `Area of circle segment: ${ area . toFixed ( 5 ) } square units` ;
3315+ return ;
3316+
3317+ }
3318+
3319+ else if ( ! isNaN ( length ) || ! isNaN ( height ) || height > 0 || length > 0 ) {
3320+
32923321const ratio = 2 * height / length ;
32933322
32943323 // Segment validity check
@@ -3312,13 +3341,14 @@ <h3 itemprop="name" style="margin:7px">Area of a Circle Segment</h3>
33123341 document . getElementById ( 'segment-area' ) . innerText =
33133342 `Area of semi-circle: ${ area . toFixed ( 5 ) } square units` ;
33143343 return ;
3315- }
3316-
3344+ }
3345+
3346+
33173347 document . getElementById ( 'segment-area' ) . innerText =
33183348 `Area: ${ area . toFixed ( 5 ) } square units` ;
3319- }
3320-
3321- document . getElementById ( 'segment -length' ) . addEventListener ( 'input' , updateSegmentArea ) ;
3349+ }
3350+
3351+ document . getElementById ( 'chord -length' ) . addEventListener ( 'input' , updateSegmentArea ) ;
33223352 document . getElementById ( 'segment-height' ) . addEventListener ( 'input' , updateSegmentArea ) ;
33233353</ script >
33243354< p id ="segment-area "> </ p >
0 commit comments