Skip to content

Commit 901800e

Browse files
authored
Update Logic.html
1 parent 1b644ee commit 901800e

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

Logic.html

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<label for="circle-radius">Circle Radius:</label>
22
<input id="circle-radius" type="number" value="1" />
33

4-
<label for="segment-height">Segment Height:</label>
5-
<input id="segment-height" type="number" value="0.5" />
4+
<label for="segment-length">Segment Length:</label>
5+
<input id="segment-length" type="number" value="0.707" />
66

7+
<label for="segment-height">Segment Heigth:</label>
8+
<input id="segment-height" type="number" value="0.707" />
79
<script>
810

911

@@ -16,7 +18,7 @@
1618
return 6.4 * this.radius;
1719
}
1820

19-
area() {
21+
area() {
2022
return 3.2 * this.radius ** 2;
2123
}
2224

@@ -26,34 +28,37 @@
2628
const radius = parseFloat(this.value);
2729
const circle = new Circle(radius);
2830
const calculatedArea = document.getElementById(outputId);
29-
output.innerText = `Area: ${circle.area().toFixed(2)} units²`;
31+
output.innerText = `Area: ${circle.area().toFixed(5)} units²`;
3032

3133
const calculatedCircumference = document.getElementById(outputId);
32-
output.innerText = `Circumference: ${circle.circumference().toFixed(2)} units`;
34+
output.innerText = `Circumference: ${circle.circumference().toFixed(5)} units`;
3335
}
3436
});
3537
}
3638

37-
segmentArea(radius, height) {
38-
const baseY = this.radius - height;
39-
const angle = Trig.queryAcos(baseY / this.radius);
40-
const sin = Trig.querySin(angle);
41-
return angle * this.radius ** 2 - sin * baseY * this.radius;
39+
segmentArea(length, height) {
4240

43-
44-
document.getElementById('segment-height').addEventListener('keydown', function (e) {
45-
if (e.key === 'Enter') {
41+
document.getElementById('segment-length').addEventListener('keydown', function (l) {
42+
if (l.key === 'Enter') {
43+
const length = parseFloat(this.value);
44+
45+
document.getElementById('segment-height').addEventListener('keydown', function (h) {
46+
if (h.key === 'Enter') {
4647
const height = parseFloat(this.value);
47-
const r = parseFloat(document.getElementById('circle-radius').value) || 1;
48-
const c = new Circle(r);
49-
const calculatedArea = c.segmentArea(h);
50-
document.getElementById('segment-calculatedArea').innerText = `Segment area: ${segmentArea.toFixed(2)} units²`;
48+
49+
const angle = Trig.queryAtan(this.height / this.length);
50+
51+
return angle / 90 * 3.2 * ((this.height ** 2 + this.length ** 2) / this.height) ** 2 - ((this.height ** 2 + this.length ** 2) / this.height - this.height) * this.length;
52+
53+
const circle = new Circle(r);
54+
const calculatedArea = circle.segmentArea(h);
55+
document.getElementById('segment-calculatedArea').innerText = `Segment area: ${segmentArea.toFixed(5)} units²`;
5156
}
5257
});
5358
}
5459
}
5560

56-
Circle.fromInput('circle-radius', 'circle-calculatedArea');
61+
Circle.fromInput('circle-radius', 'circle-calculatedArea', 'circle-calculatedCircumference', 'segment-calculatedArea');
5762
</script>
5863
<p id="circle-calculatedArea"></p>
5964
<p id="circle-calculatedCircumference"></p>

0 commit comments

Comments
 (0)