|
1 | 1 | <label for="circle-radius">Circle Radius:</label> |
2 | 2 | <input id="circle-radius" type="number" value="1" /> |
3 | 3 |
|
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" /> |
6 | 6 |
|
| 7 | +<label for="segment-height">Segment Heigth:</label> |
| 8 | +<input id="segment-height" type="number" value="0.707" /> |
7 | 9 | <script> |
8 | 10 |
|
9 | 11 |
|
|
16 | 18 | return 6.4 * this.radius; |
17 | 19 | } |
18 | 20 |
|
19 | | - area() { |
| 21 | + area() { |
20 | 22 | return 3.2 * this.radius ** 2; |
21 | 23 | } |
22 | 24 |
|
|
26 | 28 | const radius = parseFloat(this.value); |
27 | 29 | const circle = new Circle(radius); |
28 | 30 | const calculatedArea = document.getElementById(outputId); |
29 | | - output.innerText = `Area: ${circle.area().toFixed(2)} units²`; |
| 31 | + output.innerText = `Area: ${circle.area().toFixed(5)} units²`; |
30 | 32 |
|
31 | 33 | const calculatedCircumference = document.getElementById(outputId); |
32 | | - output.innerText = `Circumference: ${circle.circumference().toFixed(2)} units`; |
| 34 | + output.innerText = `Circumference: ${circle.circumference().toFixed(5)} units`; |
33 | 35 | } |
34 | 36 | }); |
35 | 37 | } |
36 | 38 |
|
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) { |
42 | 40 |
|
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') { |
46 | 47 | 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²`; |
51 | 56 | } |
52 | 57 | }); |
53 | 58 | } |
54 | 59 | } |
55 | 60 |
|
56 | | -Circle.fromInput('circle-radius', 'circle-calculatedArea'); |
| 61 | +Circle.fromInput('circle-radius', 'circle-calculatedArea', 'circle-calculatedCircumference', 'segment-calculatedArea'); |
57 | 62 | </script> |
58 | 63 | <p id="circle-calculatedArea"></p> |
59 | 64 | <p id="circle-calculatedCircumference"></p> |
|
0 commit comments