|
23 | 23 | } |
24 | 24 |
|
25 | 25 | static fromInput(inputId, outputId) { |
26 | | - document.getElementById(inputId).addEventListener('keydown', function (e) { |
27 | | - if (e.key === 'Enter') { |
| 26 | + document.getElementById('circle-radius').addEventListener('keydown', function (cr) { |
| 27 | + if (cr.key === 'Enter') { |
28 | 28 | const radius = parseFloat(this.value); |
29 | 29 | const circle = new Circle(radius); |
30 | 30 | const calculatedArea = document.getElementById(outputId); |
|
36 | 36 | }); |
37 | 37 | } |
38 | 38 |
|
39 | | - segmentArea(length, height) { |
| 39 | + segment(length, height) { |
40 | 40 |
|
41 | 41 | document.getElementById('segment-length').addEventListener('keydown', function (l) { |
42 | | - if (l.key === 'Enter') { |
| 42 | + if (sl.key === 'Enter') { |
43 | 43 | const length = parseFloat(this.value); |
44 | 44 |
|
45 | | - document.getElementById('segment-height').addEventListener('keydown', function (h) { |
46 | | - if (h.key === 'Enter') { |
| 45 | + document.getElementById('segment-height').addEventListener('keydown', function (h) { |
| 46 | + if (sh.key === 'Enter') { |
47 | 47 | const height = parseFloat(this.value); |
48 | 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; |
| 49 | + const angle = Trig.queryAtan(this.height / this.length); |
52 | 50 |
|
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 | + const circle = new Circle(((this.height ** 2 + this.length ** 2) / this.height)); |
| 52 | + const area = circle.area(((this.height ** 2 + this.length ** 2) / this.height)) * angle / 90 - ((this.height ** 2 + this.length ** 2) / this.height - this.height) * this.length; |
| 53 | + document.getElementById('segment-area').innerText = `Segment area: ${area.toFixed(5)} units²`; |
56 | 54 | } |
57 | 55 | }); |
58 | 56 | } |
|
0 commit comments