-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40bfd25
commit 9f46acd
Showing
1 changed file
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<!-- Copyright (C) 2024 Beckett Berberich and Isaac Kamionkowski. All rights reserved. --> | ||
<title>Triangle Calculator</title> | ||
<style> | ||
.tool { | ||
position: absolute; | ||
top: 10%; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
display: none; | ||
} | ||
|
||
tr { | ||
padding: 5px; | ||
} | ||
|
||
td { | ||
padding: 5px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<noscript>You must have JavaScript enabled to use this.</noscript> | ||
<table style="margin: 0 auto; width: 500px; margin-top: 10%;"> | ||
<tr> | ||
<td> | ||
<table> | ||
<tr> | ||
<td><button id="drg" onclick="drg();">Degrees</button></td> | ||
<td></td> | ||
<td></td> | ||
</tr> | ||
<tr> | ||
<td>Angle</td> | ||
<td><button id="t_swp" onclick="swp('t_swp');">Input</button></td> | ||
<td><input id="t" type="number" step="any" min="-999999" max="999999" width="10"></td> | ||
</tr> | ||
<tr> | ||
<td>Adjacent</td> | ||
<td><button id="a_swp" onclick="swp('a_swp');">Input</button></td> | ||
<td><input id="a" type="number" step="any" min="-999999" max="999999" width="10"></td> | ||
</tr> | ||
<tr> | ||
<td>Opposite</td> | ||
<td><button id="o_swp" onclick="swp('o_swp');">Input</button></td> | ||
<td><input id="o" type="number" step="any" min="-999999" max="999999" width="10"></td> | ||
</tr> | ||
<tr> | ||
<td>Hypotenuse</td> | ||
<td><button id="h_swp" onclick="swp('h_swp');">Input</button></td> | ||
<td><input id="h" type="number" step="any" min="-999999" max="999999" width="10"></td> | ||
</tr> | ||
<tr> | ||
<td><button id="main" onclick="compute();">Calculate</button></td> | ||
</tr> | ||
</table> | ||
</td> | ||
<td> | ||
<img src="https://2dskyblokc.github.io/triangle.png" width="300" height="300" alt="A diagram of a triangle, with angle, hypotenuse, adjacent, opposite marked." style="display: inline-block;"> | ||
</td> | ||
</tr> | ||
<tr> | ||
<table style="margin: 0 auto; width: 250px;"> | ||
<tr> | ||
<td>Sin:</td> | ||
<td id="sin"></td> | ||
<td>Csc:</td> | ||
<td id="csc"></td> | ||
</tr> | ||
<tr> | ||
<td>Cos:</td> | ||
<td id="cos"></td> | ||
<td>Sec:</td> | ||
<td id="sec"></td> | ||
</tr> | ||
<tr> | ||
<td>Tan:</td> | ||
<td id="tan"></td> | ||
<td>Cot:</td> | ||
<td id="cot"></td> | ||
</tr> | ||
</table> | ||
</tr> | ||
</table> | ||
<script> | ||
|
||
let ostates = { | ||
t_swp: false, | ||
a_swp: false, | ||
o_swp: false, | ||
h_swp: false, | ||
}; | ||
|
||
let drgV = 180/Math.PI; | ||
|
||
function compute() { | ||
if ((+ostates.t_swp + ostates.a_swp + ostates.o_swp + ostates.h_swp) > 2) { | ||
alert('Must have less than 3 outputs'); | ||
return; | ||
}; | ||
let t_elt = document.getElementById('t'); | ||
let a_elt = document.getElementById('a'); | ||
let o_elt = document.getElementById('o'); | ||
let h_elt = document.getElementById('h'); | ||
let t = parseFloat(t_elt.value); | ||
let a = parseFloat(a_elt.value); | ||
let o = parseFloat(o_elt.value); | ||
let h = parseFloat(h_elt.value); | ||
if (ostates.t_swp) { | ||
if (ostates.a_swp) { | ||
t = Math.asin(o/h)*drgV; | ||
a = Math.sqrt(h**2 - o**2); | ||
} else if (ostates.o_swp) { | ||
t = Math.acos(a/h)*drgV; | ||
o = Math.sqrt(h**2 - a**2); | ||
} else { | ||
t = Math.atan(o/a)*drgV; | ||
h = Math.sqrt(a**2 + o**2); | ||
}; | ||
} else { | ||
if (!ostates.a_swp) { | ||
o = a*Math.tan(t/drgV); | ||
h = a/Math.cos(t/drgV); | ||
} else if (!ostates.o_swp) { | ||
a = o/Math.tan(t/drgV); | ||
h = o/Math.sin(t/drgV); | ||
} else { | ||
o = h*Math.sin(t/drgV); | ||
a = h*Math.cos(t/drgV); | ||
}; | ||
}; | ||
t_elt.value = t; | ||
a_elt.value = a; | ||
o_elt.value = o; | ||
h_elt.value = h; | ||
document.getElementById('sin').textContent = Math.sin(t/drgV); | ||
document.getElementById('cos').textContent = Math.cos(t/drgV); | ||
document.getElementById('tan').textContent = Math.tan(t/drgV); | ||
document.getElementById('cot').textContent = 1/Math.sin(t/drgV); | ||
document.getElementById('sec').textContent = 1/Math.cos(t/drgV); | ||
document.getElementById('csc').textContent = 1/Math.tan(t/drgV); | ||
}; | ||
|
||
function drg() { | ||
let elt = document.getElementById("drg"); | ||
const curr = elt.textContent; | ||
if (curr == "Degrees") { | ||
elt.textContent = "Radians"; | ||
drgV= 1; | ||
} else if (curr == "Radians") { | ||
elt.textContent = "Gradians"; | ||
drgV = 200/Math.PI; | ||
} else { | ||
elt.textContent = "Degrees"; | ||
drgV = 180/Math.PI; | ||
}; | ||
}; | ||
|
||
function swp(id) { | ||
let elt = document.getElementById(id); | ||
if (elt.textContent == "Input") { | ||
elt.textContent = "Output"; | ||
} else { | ||
elt.textContent = "Input"; | ||
}; | ||
ostates[id] = !ostates[id]; | ||
}; | ||
|
||
</script> | ||
</body> | ||
</html> |