Skip to content

Commit 76e58c8

Browse files
authored
Update index.html
1 parent 5abbddd commit 76e58c8

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

index.html

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3269,15 +3269,15 @@ <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">
32723273
<label for="segment-height">Height:</label>
3273-
<input id="segment-height" type="number" value="1" step="any">
3274+
<input id="segment-height" type="number" step="any">
32743275
<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">
3276+
<label for="chord-length">Chord Length:</label>
3277+
<input id="chord-length" type="number" step="any">
32783278
<br>
3279-
<label for="segment-height">Circle Radius:</label>
3280-
<input id="parent-radius" type="number" value="1" step="any">
3279+
<label for="parent-radius">Circle Radius:</label>
3280+
<input id="parent-radius" type="number" step="any">
32813281
<script>
32823282
function segmentArea(length, height, angle, radius) {
32833283
return angle * radius ** 2 - (radius - height) * length / 2;
@@ -3293,30 +3293,29 @@ <h3 itemprop="name" style="margin:7px">Area of a Circle Segment</h3>
32933293
return;
32943294
}
32953295

3296-
// If height and parent radius is known
3296+
// If height and parent radius are known
32973297

3298-
else if (!isNaN(height) || !isNaN(radius)|| height > 0 || radius > 0) {
3298+
if (!isNaN(height) || isNaN(length)|| !isNaN(radius)|| height > 0 || radius > 0) {
32993299

3300-
const ratio = (radius - height) / radius;
3301-
33023300
// Segment validity check
33033301

33043302

3305-
if (ratio > 1) {
3306-
document.getElementById('segment-area').innerText = 'This ratio is out of range';
3303+
if (height > radius) {
3304+
document.getElementById('segment-area').innerText = 'The height of a circle segment is shorter than the parent radius.';
33073305
return;
33083306
}
3309-
3310-
const angle = parseFloat(Acos(ratio));
3311-
const length = parseFloat(2 * sin(angle) * radius);
3307+
3308+
const ratio = (radius - height) / radius;
3309+
const angle = parseFloat(Acos(ratio));
3310+
const length = parseFloat(2 * sqrt(radius**2 - (radius - height)**2);
33123311

33133312
document.getElementById('segment-area').innerText =
3314-
`Area of circle segment: ${area.toFixed(5)} square units`;
3315-
return;
3316-
3313+
`Area: ${area.toFixed(5)} square units`;
33173314
}
3315+
3316+
33183317

3319-
else if (!isNaN(length) || !isNaN(height)|| height > 0 || length > 0) {
3318+
if (!isNaN(height) || !isNaN(length)|| || isNaN(radius) height > 0 || length > 0) {
33203319

33213320
const ratio = 2 * height / length;
33223321

@@ -3340,13 +3339,14 @@ <h3 itemprop="name" style="margin:7px">Area of a Circle Segment</h3>
33403339
if ( ratio === 1) {
33413340
document.getElementById('segment-area').innerText =
33423341
`Area of semi-circle: ${area.toFixed(5)} square units`;
3343-
return;
33443342
}
3345-
3346-
3347-
document.getElementById('segment-area').innerText =
3343+
3344+
document.getElementById('segment-area').innerText =
33483345
`Area: ${area.toFixed(5)} square units`;
3349-
}
3346+
3347+
}
3348+
3349+
}
33503350

33513351
document.getElementById('chord-length').addEventListener('input', updateSegmentArea);
33523352
document.getElementById('segment-height').addEventListener('input', updateSegmentArea);

0 commit comments

Comments
 (0)