@@ -3034,7 +3034,6 @@ <h3 itemprop="eduQuestionType" style="margin:7px">Area of a Circle Segment</h3>
30343034< meta itemprop ="disambiguatingDescription " content ="Area based on the A(circle)=3.2*radius^2 formula, instead of the pi=3.14... approximation ">
30353035< meta itemprop ="usageInfo " content ="Enter the segment height and either the chord length or the radius of the parent circle. The other value will be discarded in the result. ">
30363036< label for ="segment-height "> Segment Height:</ label >
3037- < label for ="segment-height "> Segment Height:</ label >
30383037< input id ="segment-height " type ="number " step ="any ">
30393038< br >
30403039< label for ="chord-length "> Chord Length:</ label >
@@ -3053,7 +3052,6 @@ <h3 itemprop="eduQuestionType" style="margin:7px">Area of a Circle Segment</h3>
30533052 const rInput = document . getElementById ( 'parent-radius' ) ;
30543053 const output = document . getElementById ( 'segment-area' ) ;
30553054
3056- // Detect which field the user is typing in
30573055 const activeElement = document . activeElement ;
30583056 if ( activeElement . id === "segment-height" ) userEntered . h = true ;
30593057 if ( activeElement . id === "chord-length" ) userEntered . l = true ;
@@ -3074,51 +3072,52 @@ <h3 itemprop="eduQuestionType" style="margin:7px">Area of a Circle Segment</h3>
30743072 return ;
30753073 }
30763074
3077- // Workflow A: height + radius → derive length
3075+ // If height and radius is known → derive length
30783076 if ( userEntered . h && userEntered . r && ! userEntered . l && ! isNaN ( h ) && ! isNaN ( r ) ) {
30793077 let angle = Acos ( ( r - h ) / r ) ;
30803078 l = 2 * r * sin ( angle ) ;
30813079 lInput . value = l . toFixed ( 5 ) ;
30823080 autoFilledField = "chord-length" ;
3083-
3084- let area = angle * r ** 2 - ( r - h ) * ( l / 2 ) ;
3085- output . innerText = ( h === r || h === l / 2 || l === 2 * r )
3086- ? `Semicircle area: ${ area . toFixed ( 5 ) } square units`
3087- : `Area: ${ area . toFixed ( 5 ) } square units` ;
3088- return ;
30893081 }
30903082
3091- // Workflow B: height + length → derive radius
3083+ // If height and length is known → derive radius
30923084 if ( userEntered . h && userEntered . l && ! userEntered . r && ! isNaN ( h ) && ! isNaN ( l ) ) {
30933085 r = ( l ** 2 + 4 * h ** 2 ) / ( 8 * h ) ;
30943086 rInput . value = r . toFixed ( 5 ) ;
30953087 autoFilledField = "parent-radius" ;
3096-
3097- let angle = Acos ( ( r - h ) / r ) ;
3098- let area = angle * r ** 2 - ( r - h ) * ( l / 2 ) ;
3099- output . innerText = ( h === r || h === l / 2 || l === 2 * r )
3100- ? `Semicircle area: ${ area . toFixed ( 5 ) } square units`
3101- : `Area: ${ area . toFixed ( 5 ) } square units` ;
3102- return ;
31033088 }
31043089
3105- // Workflow C: length + radius → derive height
3090+ // If length and radius is known → derive height
31063091 if ( userEntered . l && userEntered . r && ! userEntered . h && ! isNaN ( l ) && ! isNaN ( r ) ) {
31073092 h = r - Math . sqrt ( r ** 2 - ( l / 2 ) ** 2 ) ;
31083093 hInput . value = h . toFixed ( 5 ) ;
31093094 autoFilledField = "segment-height" ;
3095+ }
31103096
3111- let angle = Acos ( ( r - h ) / r ) ;
3112- let area = angle * r ** 2 - ( r - h ) * ( l / 2 ) ;
3113- output . innerText = ( h === r || h === l / 2 || l === 2 * r )
3114- ? `Semicircle area: ${ area . toFixed ( 5 ) } square units`
3115- : `Area: ${ area . toFixed ( 5 ) } square units` ;
3097+ // If fewer than 2 inputs → prompt
3098+ if ( [ ! isNaN ( h ) , ! isNaN ( l ) , ! isNaN ( r ) ] . filter ( Boolean ) . length < 2 ) {
3099+ output . innerText = "Enter one more property to compute." ;
31163100 return ;
31173101 }
31183102
3119- // If only one field filled
3120- if ( [ ! isNaN ( h ) , ! isNaN ( l ) , ! isNaN ( r ) ] . filter ( Boolean ) . length < 2 ) {
3121- output . innerText = "Enter one more value to compute." ;
3103+ // Proportion checks (replace output if triggered)
3104+ if ( l < 2 * h ) {
3105+ output . innerText = "The chord length must be at least twice the height." ;
3106+ return ;
3107+ }
3108+ if ( l / h > 30 ) {
3109+ output . innerText = "Out of range: chord-to-height ratio exceeds 30." ;
3110+ return ;
3111+ }
3112+
3113+ // Unified area calculation
3114+ let angle = Acos ( ( r - h ) / r ) ;
3115+ let area = angle * r ** 2 - ( r - h ) * ( l / 2 ) ;
3116+
3117+ if ( h === r || h === l / 2 || l === 2 * r ) {
3118+ output . innerText = `Semicircle area: ${ area . toFixed ( 5 ) } square units` ;
3119+ } else {
3120+ output . innerText = `Area: ${ area . toFixed ( 5 ) } square units` ;
31223121 }
31233122}
31243123
0 commit comments