commit 6185df8d584f64531665d22f7840c06918063bf7
parent 1c1d5b40a9cb2552065e9a9ee992fd3bb735c600
Author: therealFIGBERT <figbertwelner@gmail.com>
Date: Sat, 9 Nov 2019 12:16:32 -0800
Linting, updating, and clarifying JS, mildly beautifying the site, adding .gitignore
Diffstat:
13 files changed, 750 insertions(+), 440 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1 @@
+.DS_Store
diff --git a/sizecalc/index.html b/angular-distance-real-size-solver/index.html
diff --git a/angular-distance-real-size-solver/sizecalc.js b/angular-distance-real-size-solver/sizecalc.js
@@ -0,0 +1,76 @@
+var type;
+
+function show(elements) {
+ "use strict";
+ for (var a = 0; a < elements.length; a++) {
+ elements[a].style.display = "inline";
+ }
+}
+
+function hide(elements) {
+ "use strict";
+ for (var a = 0; a < elements.length; a++) {
+ elements[a].style.display = "none";
+ }
+}
+
+function reset(elements) {
+ "use strict";
+ for (var a = 0; a < elements.length; a++) {
+ elements[a].value = "";
+ }
+}
+
+function setUp(selection) {
+ "use strict";
+ type = selection;
+ document.getElementById("sizeIn").style.display = "block";
+ hide(document.getElementsByClassName("ins"));
+ reset(document.getElementsByClassName("numinput"));
+ if (type === "a") {
+ show(document.getElementsByClassName("a"));
+ } else if (type === "D") {
+ show(document.getElementsByClassName("D"));
+ } else {
+ show(document.getElementsByClassName("d"));
+ }
+ document.getElementById("out").style.display = "none";
+}
+
+function angularSize(size, distance) {
+ "use strict";
+ return (180 * size) / (3.14 * distance);
+}
+
+function realSize(angle, distance) {
+ "use strict";
+ return (angle * 3.14 * distance) / 180;
+}
+
+function calcDistance(size, angle) {
+ "use strict";
+ return (180 * size) / (3.14 * angle);
+}
+
+function actionManager(angle, size, distance) {
+ "use strict";
+ if (type === "a") {
+ document.getElementById("out").style.display = "block";
+ document.getElementById("numOut").innerHTML =
+ "𝛼 = " + angularSize(size, distance);
+ } else if (type === "D") {
+ document.getElementById("out").style.display = "block";
+ document.getElementById("numOut").innerHTML =
+ "D = " + realSize(angle, distance);
+ } else {
+ document.getElementById("out").style.display = "block";
+ document.getElementById("numOut").innerHTML =
+ "d = " + calcDistance(size, angle);
+ }
+}
+/*
+Test values:
+𝛼 = 0.266513692671216
+D = 432168.6
+d = 92955810
+*/
+\ No newline at end of file
diff --git a/consecutive-number-solver/consecutiveNum.js b/consecutive-number-solver/consecutiveNum.js
@@ -0,0 +1,189 @@
+function getSum(total, num) {
+ "use strict";
+ return total + num;
+}
+
+function solveConsec(amount, sum, type) {
+ "use strict";
+ var numAmount = parseInt(amount, 10),
+ numSum = parseInt(sum, 10),
+ smallestNum = 0,
+ allNums = [];
+ switch (type) {
+ case "odd":
+ if (numSum > 0) {
+ smallestNum = 1;
+ var a = 0;
+ for (var b = 0; b < numAmount; b++) {
+ allNums.push(smallestNum + a);
+ a += 2;
+ }
+ while (
+ allNums.reduce(getSum) !== numSum &&
+ allNums.reduce(getSum) < numSum
+ ) {
+ for (var c = 0; c < allNums.length; c++) {
+ allNums[c] += 2;
+ }
+ }
+ if (allNums.reduce(getSum) > numSum) {
+ document.getElementById("outText").innerHTML =
+ "Unfortunately, the combination entered does not have an answer. Try again with another set of values.";
+ } else {
+ document.getElementById("outText").innerHTML =
+ "Success! The " +
+ numAmount +
+ " consecutive numbers that equal " +
+ numSum +
+ " are " +
+ allNums +
+ ".";
+ }
+ } else if (numSum < 0) {
+ smallestNum = -1;
+ var d = 0;
+ for (var e = 0; e < numAmount; e++) {
+ allNums.push(smallestNum + d);
+ d -= 2;
+ }
+ while (
+ allNums.reduce(getSum) !== numSum &&
+ allNums.reduce(getSum) > numSum
+ ) {
+ for (var f = 0; f < allNums.length; f++) {
+ allNums[f] -= 2;
+ }
+ }
+ if (allNums.reduce(getSum) > numSum) {
+ document.getElementById("outText").innerHTML =
+ "Unfortunately, the combination entered does not have an answer. Try again with another set of values.";
+ } else {
+ document.getElementById("outText").innerHTML =
+ "Success! The " +
+ numAmount +
+ " consecutive numbers that equal " +
+ numSum +
+ " are " +
+ allNums +
+ ".";
+ }
+ }
+ break;
+ case "even":
+ if (numSum > 0) {
+ var a = 0;
+ for (var b = 0; b < numAmount; b++) {
+ allNums.push(smallestNum + a);
+ a += 2;
+ }
+ while (
+ allNums.reduce(getSum) !== numSum &&
+ allNums.reduce(getSum) < numSum
+ ) {
+ for (var c = 0; c < allNums.length; c++) {
+ allNums[c] += 2;
+ }
+ }
+ if (allNums.reduce(getSum) > numSum) {
+ document.getElementById("outText").innerHTML =
+ "Unfortunately, the combination entered does not have an answer. Try again with another set of values.";
+ } else {
+ document.getElementById("outText").innerHTML =
+ "Success! The " +
+ numAmount +
+ " consecutive numbers that equal " +
+ numSum +
+ " are " +
+ allNums +
+ ".";
+ }
+ } else if (numSum < 0) {
+ var d = 0;
+ for (var e = 0; e < numAmount; e++) {
+ allNums.push(smallestNum + d);
+ d -= 2;
+ }
+ while (
+ allNums.reduce(getSum) !== numSum &&
+ allNums.reduce(getSum) > numSum
+ ) {
+ for (var f = 0; f < allNums.length; f++) {
+ allNums[f] -= 2;
+ }
+ }
+ if (allNums.reduce(getSum) > numSum) {
+ document.getElementById("outText").innerHTML =
+ "Unfortunately, the combination entered does not have an answer. Try again with another set of values.";
+ } else {
+ document.getElementById("outText").innerHTML =
+ "Success! The " +
+ numAmount +
+ " consecutive numbers that equal " +
+ numSum +
+ " are " +
+ allNums +
+ ".";
+ }
+ }
+ break;
+ case "mixed":
+ if (numSum > 0) {
+ for (var g = 0; g < numAmount; g++) {
+ allNums.push(smallestNum + g);
+ }
+ while (
+ allNums.reduce(getSum) !== numSum &&
+ allNums.reduce(getSum) < numSum
+ ) {
+ for (var h = 0; h < allNums.length; h++) {
+ allNums[h]++;
+ }
+ }
+ if (allNums.reduce(getSum) > numSum) {
+ document.getElementById("outText").innerHTML =
+ "Unfortunately, the combination entered does not have an answer. Try again with another set of values.";
+ } else {
+ document.getElementById("outText").innerHTML =
+ "Success! The " +
+ numAmount +
+ " consecutive numbers that equal " +
+ numSum +
+ " are " +
+ allNums +
+ ".";
+ }
+ } else if (numSum < 0) {
+ var i = 0;
+ for (var j = 0; j < numAmount; j++) {
+ allNums.push(smallestNum + i);
+ i--;
+ }
+ while (
+ allNums.reduce(getSum) !== numSum &&
+ allNums.reduce(getSum) > numSum
+ ) {
+ for (var k = 0; k < allNums.length; k++) {
+ allNums[k]--;
+ }
+ }
+ if (allNums.reduce(getSum) > numSum) {
+ document.getElementById("outText").innerHTML =
+ "Unfortunately, the combination entered does not have an answer. Try again with another set of values.";
+ } else {
+ document.getElementById("outText").innerHTML =
+ "Success! The " +
+ numAmount +
+ " consecutive numbers that equal " +
+ numSum +
+ " are " +
+ allNums +
+ ".";
+ }
+ }
+ break;
+ }
+}
+/*
+Test values:
+4 consequtive even integers equal 100
+*/
+\ No newline at end of file
diff --git a/consecutiveNum/index.html b/consecutive-number-solver/index.html
diff --git a/consecutiveNum/consecutiveNum.js b/consecutiveNum/consecutiveNum.js
@@ -1,124 +0,0 @@
-function getSum(total, num) {
- "use strict";
- return total + num;
-}
-
-function solveConsec(amount, sum, type) {
- "use strict";
- var
- numAmount = parseInt(amount, 10),
- numSum = parseInt(sum, 10),
- smallestNum = 0,
- allNums = [];
- switch (type) {
- case "odd":
- if (numSum > 0) {
- smallestNum = 1;
- var a = 0;
- for (var b = 0; b < numAmount; b++) {
- allNums.push(smallestNum + a);
- a += 2;
- }
- while (allNums.reduce(getSum) !== numSum && allNums.reduce(getSum) < numSum) {
- for (var c = 0; c < allNums.length; c++) {
- allNums[c] += 2;
- }
- }
- if (allNums.reduce(getSum) > numSum) {
- document.getElementById("outText").innerHTML = "Unfortunately, the combination entered does not have an answer. Try again with another set of values.";
- } else {
- document.getElementById("outText").innerHTML = "Success! The " + numAmount + " consecutive numbers that equal " + numSum + " are " + allNums + ".";
- }
- } else if (numSum < 0) {
- smallestNum = -1;
- var d = 0;
- for (var e = 0; e < numAmount; e++) {
- allNums.push(smallestNum + d);
- d -= 2;
- }
- while (allNums.reduce(getSum) !== numSum && allNums.reduce(getSum) > numSum) {
- for (var f = 0; f < allNums.length; f++) {
- allNums[f] -= 2;
- }
- }
- if (allNums.reduce(getSum) > numSum) {
- document.getElementById("outText").innerHTML = "Unfortunately, the combination entered does not have an answer. Try again with another set of values.";
- } else {
- document.getElementById("outText").innerHTML = "Success! The " + numAmount + " consecutive numbers that equal " + numSum + " are " + allNums + ".";
- }
- }
- break;
- case "even":
- if (numSum > 0) {
- var a = 0;
- for (var b = 0; b < numAmount; b++) {
- allNums.push(smallestNum + a);
- a += 2;
- }
- while (allNums.reduce(getSum) !== numSum && allNums.reduce(getSum) < numSum) {
- for (var c = 0; c < allNums.length; c++) {
- allNums[c] += 2;
- }
- }
- if (allNums.reduce(getSum) > numSum) {
- document.getElementById("outText").innerHTML = "Unfortunately, the combination entered does not have an answer. Try again with another set of values.";
- } else {
- document.getElementById("outText").innerHTML = "Success! The " + numAmount + " consecutive numbers that equal " + numSum + " are " + allNums + ".";
- }
- } else if (numSum < 0) {
- var d = 0;
- for (var e = 0; e < numAmount; e++) {
- allNums.push(smallestNum + d);
- d -= 2;
- }
- while (allNums.reduce(getSum) !== numSum && allNums.reduce(getSum) > numSum) {
- for (var f = 0; f < allNums.length; f++) {
- allNums[f] -= 2;
- }
- }
- if (allNums.reduce(getSum) > numSum) {
- document.getElementById("outText").innerHTML = "Unfortunately, the combination entered does not have an answer. Try again with another set of values.";
- } else {
- document.getElementById("outText").innerHTML = "Success! The " + numAmount + " consecutive numbers that equal " + numSum + " are " + allNums + ".";
- }
- }
- break;
- case "mixed":
- if (numSum > 0) {
- for (var g = 0; g < numAmount; g++) {
- allNums.push(smallestNum + g);
- }
- while (allNums.reduce(getSum) !== numSum && allNums.reduce(getSum) < numSum) {
- for (var h = 0; h < allNums.length; h++) {
- allNums[h]++;
- }
- }
- if (allNums.reduce(getSum) > numSum) {
- document.getElementById("outText").innerHTML = "Unfortunately, the combination entered does not have an answer. Try again with another set of values.";
- } else {
- document.getElementById("outText").innerHTML = "Success! The " + numAmount + " consecutive numbers that equal " + numSum + " are " + allNums + ".";
- }
- } else if (numSum < 0) {
- var i = 0;
- for (var j = 0; j < numAmount; j++) {
- allNums.push(smallestNum + i);
- i--;
- }
- while (allNums.reduce(getSum) !== numSum && allNums.reduce(getSum) > numSum) {
- for (var k = 0; k < allNums.length; k++) {
- allNums[k]--;
- }
- }
- if (allNums.reduce(getSum) > numSum) {
- document.getElementById("outText").innerHTML = "Unfortunately, the combination entered does not have an answer. Try again with another set of values.";
- } else {
- document.getElementById("outText").innerHTML = "Success! The " + numAmount + " consecutive numbers that equal " + numSum + " are " + allNums + ".";
- }
- }
- break;
- }
-}
-/*
-Test values:
-4 consequtive even integers equal 100
-*/
-\ No newline at end of file
diff --git a/index.html b/index.html
@@ -22,14 +22,14 @@
<th class="table__color">Physics</th>
</tr>
<tr>
- <td><a href="matrix" class="table__color">Simultaneous Equation Solver</a></td>
- <td></td>
- <td><a href="sizecalc/" class="table__color">Size Calculator</a></td>
+ <td><a href="matrix-solver/" class="table__color">Simultaneous Equation Solver</a></td>
+ <td><a href="polygon-angle-solver/" class="table__color">Polygon Angle Solver</a></td>
+ <td><a href="angular-distance-real-size-solver/" class="table__color">Size Calculator</a></td>
</tr>
<tr>
- <td><a href="consecutiveNum/" class="table__color">Consecutive Number Solver</a></td>
- <td></td>
+ <td><a href="consecutive-number-solver/" class="table__color">Consecutive Number Solver</a></td>
<td></td>
+ <td><a href="motion-graph-solver/" class="table__color">Motion Graph Solver</a></td>
</tr>
</table>
<footer>
diff --git a/matrix/index.html b/matrix-solver/index.html
diff --git a/matrix-solver/matrix.js b/matrix-solver/matrix.js
@@ -0,0 +1,368 @@
+//lcm() calculates the lowest common multiple by adding the first number until it is divisible by the second.
+function lcm(numOne, numTwo) {
+ "use strict";
+ var i = numOne;
+ while (i % numTwo !== 0) {
+ i += numOne;
+ }
+ return i;
+}
+
+//invert() changes all of the values in a numerical array to their opposites (1 to -1, etc) with a for loop
+function invert(value) {
+ "use strict";
+ for (var a = 0; a < value.length; a++) {
+ value[a] = value[a] * -1;
+ }
+ return value;
+}
+
+//hide() hides arrayed html elements using the "display: none" method and a for loop
+function hide(elements) {
+ "use strict";
+ for (var b = 0; b < elements.length; b++) {
+ elements[b].style.display = "none";
+ }
+}
+
+//reset() clears html number inputs by setting their value to null
+function reset(elements) {
+ "use strict";
+ for (var c = 0; c < elements.length; c++) {
+ elements[c].value = null;
+ }
+}
+
+//show() shows arrayed html elements INLINE using a for loop
+function show(elements) {
+ "use strict";
+ for (var d = 0; d < elements.length; d++) {
+ elements[d].style.display = "inline";
+ }
+}
+
+//setUp() will determine the number of equations and variables and adjust the html accordingly.
+function setUpMatrix(num) {
+ "use strict";
+ var allW = document.getElementsByClassName("w"),
+ allZ = document.getElementsByClassName("z"),
+ all = document.getElementsByClassName("a");
+ if (num === "2") {
+ document.getElementById("equations").style.display = "block";
+ hide(allW);
+ hide(allZ);
+ document.getElementById("out").style.display = "none";
+ document.getElementById("thirdEquation").style.display = "none";
+ document.getElementById("fourthEquation").style.display = "none";
+ reset(all);
+ } else if (num === "3") {
+ document.getElementById("equations").style.display = "block";
+ hide(allW);
+ show(allZ);
+ document.getElementById("out").style.display = "none";
+ document.getElementById("thirdEquation").style.display = "block";
+ document.getElementById("fourthEquation").style.display = "none";
+ reset(all);
+ } else {
+ document.getElementById("equations").style.display = "block";
+ show(allW);
+ show(allZ);
+ document.getElementById("out").style.display = "none";
+ document.getElementById("thirdEquation").style.display = "block";
+ document.getElementById("fourthEquation").style.display = "block";
+ reset(all);
+ }
+}
+
+//answerTwo() accepts two simplified equations as input and outputs the x and y values
+function answerTwo(one, two) {
+ "use strict";
+ var y = two[2] / two[1],
+ x = (one[2] - one[1] * y) / one[0];
+ return [x, y];
+}
+
+//answerThree() accepts three simplified equations as input and outputs the x, y, and z values
+function answerThree(one, two, three) {
+ "use strict";
+ var z = three[3] / three[2],
+ y = (two[3] - two[2] * z) / two[1],
+ x = (one[3] - (one[2] * z + one[1] * y)) / one[0];
+ return [x, y, z];
+}
+
+//answerFour() accepts four simplified equations as input and outputs the w, x, y, and z values
+function answerFour(one, two, three, four) {
+ "use strict";
+ var z = four[4] / four[3],
+ y = (three[4] - three[3] * z) / three[2],
+ x = (two[4] - (two[3] * z + two[2] * y)) / two[1],
+ w = (one[4] - (one[3] * z + one[2] * y + one[1] * x)) / one[0];
+ return [w, x, y, z];
+}
+
+//solveTwoMatrix() accepts two equations as input and simplifies the second
+function solveTwoMatrix(one, two) {
+ "use strict";
+ var multOne = lcm(one[0], two[0]) / one[0],
+ multTwo = lcm(one[0], two[0]) / two[0],
+ changingOne = one.slice();
+ for (var e = 0; e < two.length; e++) {
+ changingOne[e] *= multOne;
+ two[e] *= multTwo;
+ }
+ if (changingOne[0] + two[0] !== 0) {
+ invert(changingOne);
+ }
+ for (var f = 0; f < two.length; f++) {
+ two[f] += changingOne[f];
+ }
+ return two;
+}
+
+//solveThreeMatrix() accepts three equations as input and outputs the simplified second and third
+function solveThreeMatrix(one, two, three) {
+ "use strict";
+ var simpleTwo = solveTwoMatrix(one, two),
+ simpleThree = solveTwoMatrix(one, three),
+ multTwo = lcm(simpleTwo[1], simpleThree[1]) / simpleTwo[1],
+ multThree = lcm(simpleTwo[1], simpleThree[1]) / simpleThree[1],
+ changingTwo = simpleTwo.slice();
+ for (var g = 0; g < simpleThree.length; g++) {
+ changingTwo[g] *= multTwo;
+ simpleThree[g] *= multThree;
+ }
+ if (changingTwo[1] + simpleThree[1] !== 0) {
+ invert(changingTwo);
+ }
+ for (var h = 0; h < simpleThree.length; h++) {
+ simpleThree[h] += changingTwo[h];
+ }
+ return [simpleTwo, simpleThree];
+}
+
+//solveFourMatrix() accepts four equations as input and outputs the simplified second, third, and fourth
+function solveFourMatrix(one, two, three, four) {
+ "use strict";
+ var simpleTwoThree = solveThreeMatrix(one, two, three),
+ simpleFour = solveTwoMatrix(one, four),
+ changingTwo = simpleTwoThree[0],
+ changingThree = simpleTwoThree[1],
+ multTwo = lcm(changingTwo[1], simpleFour[1]) / changingTwo[1],
+ firstMultFour = lcm(changingTwo[1], simpleFour[1]) / simpleFour[1];
+ for (var a = 0; a < simpleFour.length; a++) {
+ simpleFour[a] *= firstMultFour;
+ changingTwo[a] *= multTwo;
+ }
+ if (simpleFour[1] + changingTwo[1] !== 0) {
+ invert(changingTwo);
+ }
+ for (var b = 0; b < simpleFour.length; b++) {
+ simpleFour[b] += changingTwo[b];
+ }
+ var multThree = lcm(changingThree[2], simpleFour[2]) / changingThree[2],
+ secondMultFour = lcm(changingThree[2], simpleFour[2]) / simpleFour[2];
+ for (var c = 0; c < simpleFour.length; c++) {
+ changingThree[c] *= multThree;
+ simpleFour[c] *= secondMultFour;
+ }
+ if (simpleFour[2] + changingThree[2] !== 0) {
+ invert(changingThree);
+ }
+ for (var d = 0; d < simpleFour.length; d++) {
+ simpleFour[d] += changingThree[d];
+ }
+ return [simpleTwoThree[0], simpleTwoThree[1], simpleFour];
+}
+
+//solveMatrix() uses a combination of other functions to simplify the matrix
+function solveMatrix(dimension) {
+ "use strict";
+ if (dimension === "2") {
+ var firstXY = [
+ parseInt(document.getElementById("xOne").value),
+ parseInt(document.getElementById("yOne").value),
+ parseInt(document.getElementById("equalsOne").value)
+ ],
+ secondXY = [
+ parseInt(document.getElementById("xTwo").value),
+ parseInt(document.getElementById("yTwo").value),
+ parseInt(document.getElementById("equalsTwo").value)
+ ],
+ answerXY = solveTwoMatrix(firstXY, secondXY),
+ valuesXY = answerTwo(firstXY, answerXY);
+ show([document.getElementById("out")]);
+ hide([
+ document.getElementById("titleThree"),
+ document.getElementById("outThree"),
+ document.getElementById("titleFour"),
+ document.getElementById("outFour"),
+ document.getElementById("wValue"),
+ document.getElementById("zValue")
+ ]);
+ document.getElementById("outOne").innerHTML =
+ "[" + firstXY[0] + ", " + firstXY[1] + ", " + firstXY[2] + "]";
+ document.getElementById("outTwo").innerHTML =
+ "[" + answerXY[0] + ", " + answerXY[1] + ", " + answerXY[2] + "]";
+ document.getElementById("xValue").innerHTML = "x = " + valuesXY[0];
+ document.getElementById("yValue").innerHTML = "y = " + valuesXY[1];
+ } else if (dimension === "3") {
+ var firstXYZ = [
+ parseInt(document.getElementById("xOne").value),
+ parseInt(document.getElementById("yOne").value),
+ parseInt(document.getElementById("zOne").value),
+ parseInt(document.getElementById("equalsOne").value)
+ ],
+ secondXYZ = [
+ parseInt(document.getElementById("xTwo").value),
+ parseInt(document.getElementById("yTwo").value),
+ parseInt(document.getElementById("zTwo").value),
+ parseInt(document.getElementById("equalsTwo").value)
+ ],
+ thirdXYZ = [
+ parseInt(document.getElementById("xThree").value),
+ parseInt(document.getElementById("yThree").value),
+ parseInt(document.getElementById("zThree").value),
+ parseInt(document.getElementById("equalsThree").value)
+ ],
+ answerXYZ = solveThreeMatrix(firstXYZ, secondXYZ, thirdXYZ),
+ valuesXYZ = answerThree(firstXYZ, answerXYZ[0], answerXYZ[1]);
+ show([
+ document.getElementById("out"),
+ document.getElementById("titleThree")
+ ]);
+ document.getElementById("outThree").style.display = "block";
+ hide([
+ document.getElementById("titleFour"),
+ document.getElementById("outFour"),
+ document.getElementById("wValue")
+ ]);
+ document.getElementById("outOne").innerHTML =
+ "[" +
+ firstXYZ[0] +
+ ", " +
+ firstXYZ[1] +
+ ", " +
+ firstXYZ[2] +
+ ", " +
+ firstXYZ[3] +
+ "]";
+ document.getElementById("outTwo").innerHTML =
+ "[" +
+ answerXYZ[0][0] +
+ ", " +
+ answerXYZ[0][1] +
+ ", " +
+ answerXYZ[0][2] +
+ ", " +
+ answerXYZ[0][3] +
+ "]";
+ document.getElementById("outThree").innerHTML =
+ "[" +
+ answerXYZ[1][0] +
+ ", " +
+ answerXYZ[1][1] +
+ ", " +
+ answerXYZ[1][2] +
+ ", " +
+ answerXYZ[1][3] +
+ "]";
+ document.getElementById("xValue").innerHTML = "x = " + valuesXYZ[0];
+ document.getElementById("yValue").innerHTML = "y = " + valuesXYZ[1];
+ document.getElementById("zValue").innerHTML = "z = " + valuesXYZ[2];
+ } else {
+ var firstWXYZ = [
+ parseInt(document.getElementById("wOne").value),
+ parseInt(document.getElementById("xOne").value),
+ parseInt(document.getElementById("yOne").value),
+ parseInt(document.getElementById("zOne").value),
+ parseInt(document.getElementById("equalsOne").value)
+ ],
+ secondWXYZ = [
+ parseInt(document.getElementById("wTwo").value),
+ parseInt(document.getElementById("xTwo").value),
+ parseInt(document.getElementById("yTwo").value),
+ parseInt(document.getElementById("zTwo").value),
+ parseInt(document.getElementById("equalsTwo").value)
+ ],
+ thirdWXYZ = [
+ parseInt(document.getElementById("wThree").value),
+ parseInt(document.getElementById("xThree").value),
+ parseInt(document.getElementById("yThree").value),
+ parseInt(document.getElementById("zThree").value),
+ parseInt(document.getElementById("equalsThree").value)
+ ],
+ fourthWXYZ = [
+ parseInt(document.getElementById("wFour").value),
+ parseInt(document.getElementById("xFour").value),
+ parseInt(document.getElementById("yFour").value),
+ parseInt(document.getElementById("zFour").value),
+ parseInt(document.getElementById("equalsFour").value)
+ ],
+ answerWXYZ = solveFourMatrix(
+ firstWXYZ,
+ secondWXYZ,
+ thirdWXYZ,
+ fourthWXYZ
+ ),
+ valuesWXYZ = answerFour(
+ firstWXYZ,
+ answerWXYZ[0],
+ answerWXYZ[1],
+ answerWXYZ[2]
+ );
+ show([document.getElementById("out")]);
+ document.getElementById("outOne").innerHTML =
+ "[" +
+ firstWXYZ[0] +
+ ", " +
+ firstWXYZ[1] +
+ ", " +
+ firstWXYZ[2] +
+ ", " +
+ firstWXYZ[3] +
+ ", " +
+ firstWXYZ[4] +
+ "]";
+ document.getElementById("outTwo").innerHTML =
+ "[" +
+ answerWXYZ[0][0] +
+ ", " +
+ answerWXYZ[0][1] +
+ ", " +
+ answerWXYZ[0][2] +
+ ", " +
+ answerWXYZ[0][3] +
+ ", " +
+ answerWXYZ[0][4] +
+ "]";
+ document.getElementById("outThree").innerHTML =
+ "[" +
+ answerWXYZ[1][0] +
+ ", " +
+ answerWXYZ[1][1] +
+ ", " +
+ answerWXYZ[1][2] +
+ ", " +
+ answerWXYZ[1][3] +
+ ", " +
+ answerWXYZ[1][4] +
+ "]";
+ document.getElementById("outFour").innerHTML =
+ "[" +
+ answerWXYZ[2][0] +
+ ", " +
+ answerWXYZ[2][1] +
+ ", " +
+ answerWXYZ[2][2] +
+ ", " +
+ answerWXYZ[2][3] +
+ ", " +
+ answerWXYZ[2][4] +
+ "]";
+ document.getElementById("wValue").innerHTML = "w = " + valuesWXYZ[0];
+ document.getElementById("xValue").innerHTML = "x = " + valuesWXYZ[1];
+ document.getElementById("yValue").innerHTML = "y = " + valuesWXYZ[2];
+ document.getElementById("zValue").innerHTML = "z = " + valuesWXYZ[3];
+ }
+}
+\ No newline at end of file
diff --git a/matrix/matrix.js b/matrix/matrix.js
@@ -1,235 +0,0 @@
-//lcm() calculates the lowest common multiple by adding the first number until it is divisible by the second.
-function lcm(numOne, numTwo) {
- "use strict";
- var i = numOne;
- while (i % numTwo !== 0) {
- i += numOne;
- }
- return i;
-}
-
-//invert() changes all of the values in a numerical array to their opposites (1 to -1, etc) with a for loop
-function invert(value) {
- "use strict";
- for (var a = 0; a < value.length; a++) {
- value[a] = value[a] * -1;
- }
- return value;
-}
-
-//hide() hides arrayed html elements using the "display: none" method and a for loop
-function hide(elements) {
- "use strict";
- for (var b = 0; b < elements.length; b++) {
- elements[b].style.display = "none";
- }
-}
-
-//reset() clears html number inputs by setting their value to null
-function reset(elements) {
- "use strict";
- for (var c = 0; c < elements.length; c++) {
- elements[c].value = null;
- }
-}
-
-//show() shows arrayed html elements INLINE using a for loop
-function show(elements) {
- "use strict";
- for (var d = 0; d < elements.length; d++) {
- elements[d].style.display = "inline";
- }
-}
-
-//setUp() will determine the number of equations and variables and adjust the html accordingly.
-function setUpMatrix(num) {
- "use strict";
- var
- allW = document.getElementsByClassName("w"),
- allZ = document.getElementsByClassName("z"),
- all = document.getElementsByClassName("a");
- if (num === "2") {
- document.getElementById("equations").style.display = "block";
- hide(allW);
- hide(allZ);
- document.getElementById("out").style.display = "none";
- document.getElementById("thirdEquation").style.display = "none";
- document.getElementById("fourthEquation").style.display = "none";
- reset(all);
- } else if (num === "3") {
- document.getElementById("equations").style.display = "block";
- hide(allW);
- show(allZ);
- document.getElementById("out").style.display = "none";
- document.getElementById("thirdEquation").style.display = "block";
- document.getElementById("fourthEquation").style.display = "none";
- reset(all);
- } else {
- document.getElementById("equations").style.display = "block";
- show(allW);
- show(allZ);
- document.getElementById("out").style.display = "none";
- document.getElementById("thirdEquation").style.display = "block";
- document.getElementById("fourthEquation").style.display = "block";
- reset(all);
- }
-}
-
-//answerTwo() accepts two simplified equations as input and outputs the x and y values
-function answerTwo(one, two) {
- "use strict";
- var
- y = two[2] / two[1],
- x = (one[2] - (one[1] * y)) / one[0];
- return [x, y];
-}
-
-//answerThree() accepts three simplified equations as input and outputs the x, y, and z values
-function answerThree(one, two, three) {
- "use strict";
- var
- z = three[3] / three[2],
- y = (two[3] - (two[2] * z)) / two[1],
- x = (one[3] - ((one[2] * z) + (one[1] * y))) / one[0];
- return [x, y, z];
-}
-
-//answerFour() accepts four simplified equations as input and outputs the w, x, y, and z values
-function answerFour(one, two, three, four) {
- "use strict";
- var
- z = four[4] / four[3],
- y = (three[4] - (three[3] * z)) / three[2],
- x = (two[4] - ((two[3] * z) + (two[2] * y))) / two[1],
- w = (one[4] - ((one[3] * z) + (one[2] * y) + (one[1] * x))) / one[0];
- return [w, x, y, z];
-}
-
-//solveTwoMatrix() accepts two equations as input and simplifies the second
-function solveTwoMatrix(one, two) {
- "use strict";
- var
- multOne = lcm(one[0], two[0]) / one[0],
- multTwo = lcm(one[0], two[0]) / two[0],
- changingOne = one.slice();
- for (var e = 0; e < two.length; e++) {
- changingOne[e] *= multOne;
- two[e] *= multTwo;
- }
- if (changingOne[0] + two[0] !== 0) {
- invert(changingOne);
- }
- for (var f = 0; f < two.length; f++) {
- two[f] += changingOne[f];
- }
- return two;
-}
-
-//solveThreeMatrix() accepts three equations as input and outputs the simplified second and third
-function solveThreeMatrix(one, two, three) {
- "use strict";
- var
- simpleTwo = solveTwoMatrix(one, two),
- simpleThree = solveTwoMatrix(one, three),
- multTwo = lcm(simpleTwo[1], simpleThree[1]) / simpleTwo[1],
- multThree = lcm(simpleTwo[1], simpleThree[1]) / simpleThree[1],
- changingTwo = simpleTwo.slice();
- for (var g = 0; g < simpleThree.length; g++) {
- changingTwo[g] *= multTwo;
- simpleThree[g] *= multThree;
- }
- if (changingTwo[1] + simpleThree[1] !== 0) {
- invert(changingTwo);
- }
- for (var h = 0; h < simpleThree.length; h++) {
- simpleThree[h] += changingTwo[h];
- }
- return [simpleTwo, simpleThree];
-}
-
-//solveFourMatrix() accepts four equations as input and outputs the simplified second, third, and fourth
-function solveFourMatrix(one, two, three, four) {
- "use strict";
- var
- simpleTwoThree = solveThreeMatrix(one, two, three),
- simpleFour = solveTwoMatrix(one, four),
- changingTwo = simpleTwoThree[0],
- changingThree = simpleTwoThree[1],
- multTwo = lcm(changingTwo[1], simpleFour[1]) / changingTwo[1],
- firstMultFour = lcm(changingTwo[1], simpleFour[1]) / simpleFour[1];
- for (var a = 0; a < simpleFour.length; a++) {
- simpleFour[a] *= firstMultFour;
- changingTwo[a] *= multTwo;
- }
- if (simpleFour[1] + changingTwo[1] !== 0) {
- invert(changingTwo);
- }
- for (var b = 0; b < simpleFour.length; b++) {
- simpleFour[b] += changingTwo[b];
- }
- var
- multThree = lcm(changingThree[2], simpleFour[2]) / changingThree[2],
- secondMultFour = lcm(changingThree[2], simpleFour[2]) / simpleFour[2];
- for (var c = 0; c < simpleFour.length; c++) {
- changingThree[c] *= multThree;
- simpleFour[c] *= secondMultFour;
- }
- if (simpleFour[2] + changingThree[2] !== 0) {
- invert(changingThree);
- }
- for (var d = 0; d < simpleFour.length; d++) {
- simpleFour[d] += changingThree[d];
- }
- return [simpleTwoThree[0], simpleTwoThree[1], simpleFour];
-}
-
-//solveMatrix() uses a combination of other functions to simplify the matrix
-function solveMatrix(dimension) {
- "use strict";
- if (dimension === "2") {
- var
- firstXY = [parseInt(document.getElementById("xOne").value), parseInt(document.getElementById("yOne").value), parseInt(document.getElementById("equalsOne").value)],
- secondXY = [parseInt(document.getElementById("xTwo").value), parseInt(document.getElementById("yTwo").value), parseInt(document.getElementById("equalsTwo").value)],
- answerXY = solveTwoMatrix(firstXY, secondXY),
- valuesXY = answerTwo(firstXY, answerXY);
- show([document.getElementById("out")]);
- hide([document.getElementById("titleThree"), document.getElementById("outThree"), document.getElementById("titleFour"), document.getElementById("outFour"), document.getElementById("wValue"), document.getElementById("zValue")]);
- document.getElementById("outOne").innerHTML = "[" + firstXY[0] + ", " + firstXY[1] + ", " + firstXY[2] + "]";
- document.getElementById("outTwo").innerHTML = "[" + answerXY[0] + ", " + answerXY[1] + ", " + answerXY[2] + "]";
- document.getElementById("xValue").innerHTML = "x = " + valuesXY[0];
- document.getElementById("yValue").innerHTML = "y = " + valuesXY[1];
- } else if (dimension === "3") {
- var
- firstXYZ = [parseInt(document.getElementById("xOne").value), parseInt(document.getElementById("yOne").value), parseInt(document.getElementById("zOne").value), parseInt(document.getElementById("equalsOne").value)],
- secondXYZ = [parseInt(document.getElementById("xTwo").value), parseInt(document.getElementById("yTwo").value), parseInt(document.getElementById("zTwo").value), parseInt(document.getElementById("equalsTwo").value)],
- thirdXYZ = [parseInt(document.getElementById("xThree").value), parseInt(document.getElementById("yThree").value), parseInt(document.getElementById("zThree").value), parseInt(document.getElementById("equalsThree").value)],
- answerXYZ = solveThreeMatrix(firstXYZ, secondXYZ, thirdXYZ),
- valuesXYZ = answerThree(firstXYZ, answerXYZ[0], answerXYZ[1]);
- show([document.getElementById("out"), document.getElementById("titleThree")]);
- document.getElementById("outThree").style.display = "block";
- hide([document.getElementById("titleFour"), document.getElementById("outFour"), document.getElementById("wValue")]);
- document.getElementById("outOne").innerHTML = "[" + firstXYZ[0] + ", " + firstXYZ[1] + ", " + firstXYZ[2] + ", " + firstXYZ[3] + "]";
- document.getElementById("outTwo").innerHTML = "[" + answerXYZ[0][0] + ", " + answerXYZ[0][1] + ", " + answerXYZ[0][2] + ", " + answerXYZ[0][3] + "]";
- document.getElementById("outThree").innerHTML = "[" + answerXYZ[1][0] + ", " + answerXYZ[1][1] + ", " + answerXYZ[1][2] + ", " + answerXYZ[1][3] + "]";
- document.getElementById("xValue").innerHTML = "x = " + valuesXYZ[0];
- document.getElementById("yValue").innerHTML = "y = " + valuesXYZ[1];
- document.getElementById("zValue").innerHTML = "z = " + valuesXYZ[2];
- } else {
- var
- firstWXYZ = [parseInt(document.getElementById("wOne").value), parseInt(document.getElementById("xOne").value), parseInt(document.getElementById("yOne").value), parseInt(document.getElementById("zOne").value), parseInt(document.getElementById("equalsOne").value)],
- secondWXYZ = [parseInt(document.getElementById("wTwo").value), parseInt(document.getElementById("xTwo").value), parseInt(document.getElementById("yTwo").value), parseInt(document.getElementById("zTwo").value), parseInt(document.getElementById("equalsTwo").value)],
- thirdWXYZ = [parseInt(document.getElementById("wThree").value), parseInt(document.getElementById("xThree").value), parseInt(document.getElementById("yThree").value), parseInt(document.getElementById("zThree").value), parseInt(document.getElementById("equalsThree").value)],
- fourthWXYZ = [parseInt(document.getElementById("wFour").value), parseInt(document.getElementById("xFour").value), parseInt(document.getElementById("yFour").value), parseInt(document.getElementById("zFour").value), parseInt(document.getElementById("equalsFour").value)],
- answerWXYZ = solveFourMatrix(firstWXYZ, secondWXYZ, thirdWXYZ, fourthWXYZ),
- valuesWXYZ = answerFour(firstWXYZ, answerWXYZ[0], answerWXYZ[1], answerWXYZ[2]);
- show([document.getElementById("out")]);
- document.getElementById("outOne").innerHTML = "[" + firstWXYZ[0] + ", " + firstWXYZ[1] + ", " + firstWXYZ[2] + ", " + firstWXYZ[3] + ", " + firstWXYZ[4] + "]";
- document.getElementById("outTwo").innerHTML = "[" + answerWXYZ[0][0] + ", " + answerWXYZ[0][1] + ", " + answerWXYZ[0][2] + ", " + answerWXYZ[0][3] + ", " + answerWXYZ[0][4] + "]";
- document.getElementById("outThree").innerHTML = "[" + answerWXYZ[1][0] + ", " + answerWXYZ[1][1] + ", " + answerWXYZ[1][2] + ", " + answerWXYZ[1][3] + ", " + answerWXYZ[1][4] + "]";
- document.getElementById("outFour").innerHTML = "[" + answerWXYZ[2][0] + ", " + answerWXYZ[2][1] + ", " + answerWXYZ[2][2] + ", " + answerWXYZ[2][3] + ", " + answerWXYZ[2][4] + "]";
- document.getElementById("wValue").innerHTML = "w = " + valuesWXYZ[0];
- document.getElementById("xValue").innerHTML = "x = " + valuesWXYZ[1];
- document.getElementById("yValue").innerHTML = "y = " + valuesWXYZ[2];
- document.getElementById("zValue").innerHTML = "z = " + valuesWXYZ[3];
- }
-}
-\ No newline at end of file
diff --git a/polygon-angle-solver/index.html b/polygon-angle-solver/index.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+
+<html>
+ <head>
+ <title>FIGBERT Math - Polygon Size</title>
+ <meta charset="utf-8">
+ <link rel="stylesheet" href="../main.css" type="text/css">
+ <script type="text/javascript" src="polycalc.js" async></script>
+ </head>
+ <body>
+ <header>
+ <h1 class="pagetitle">Polygon Angle Calculator</h1>
+ <h2 class="pagetitle pagetitle__sub">by FIGBERT</h2>
+ </header>
+ <main>
+ <form>
+ <fieldset>
+ <legend>Configure the polygon</legend>
+ <label for="regular"><input id="regular" type="radio" name="typeSelect" value="0">Regular</label><br>
+ <label for="irregular"><input id="irregular" type="radio" name="typeSelect" value="1">Irregular CONVEX</label><br>
+ <label for="sides">Sides: <input id="sides" type="number" step="1" min="3" class="numinput numinput--large"></label><br>
+ <input type="button" value="Go" onclick="actionManager(typeSelect.value, sides.value)">
+ </fieldset>
+ </form>
+ <div class="hidden" id="out">
+ <h3>Output:</h3>
+ <p id="outText"></p>
+ </div>
+ </main>
+ <footer>
+ <a href="../" class="footer__text">Home</a>
+ <span class="footer__text">•</span>
+ <a href="../about/" class="footer__text">About</a>
+ <span class="footer__text">•</span>
+ <a href="../requests/" class="footer__text">Request New Program</a>
+ <span class="footer__text">•</span>
+ <a href="../submit/" class="footer__text">Submit Code</a>
+ </footer>
+ </body>
+</html>
+\ No newline at end of file
diff --git a/polygon-angle-solver/polycalc.js b/polygon-angle-solver/polycalc.js
@@ -0,0 +1,66 @@
+function errors(type, sides) {
+ "use strict";
+ var msg = "",
+ yes = false;
+ console.log(type);
+ if (type !== "0" && type !== "1") {
+ msg += "A type is required! Please select one and try again.";
+ yes = true;
+ console.log("No type apparently");
+ }
+ if (sides < 3) {
+ msg +=
+ "<br>The number of sides provided is invalid. Please enter a number greater than two and try again.";
+ yes = true;
+ console.log("There are two few?");
+ }
+ return [yes, msg];
+}
+
+function actionManager(type, sides) {
+ "use strict";
+ sides = Math.round(sides);
+ var errorTest = errors(type, sides),
+ msg = "Oops! Something broke.",
+ rounded = "";
+ if (errorTest[0]) {
+ msg = errorTest[1];
+ } else {
+ type = Number(type);
+ sides = Number(sides);
+ var totalInterior = (sides - 2) * 180;
+ if (type === 0) {
+ var eachInterior = totalInterior / sides,
+ eachExterior = 360 / sides;
+ if (eachInterior % 1 !== 0) {
+ eachInterior = Math.round(eachInterior);
+ rounded = "~";
+ }
+ if (eachExterior % 1 !== 0) {
+ eachExterior = Math.round(eachExterior);
+ rounded = "~";
+ }
+ msg =
+ "This regular polygon with " +
+ sides +
+ " sides has " +
+ totalInterior +
+ "˚ in the interior.<br>Each interior angle is equal to " +
+ rounded +
+ eachInterior +
+ "˚.<br>The exterior angles of a regular polygon always sum to 360˚<br>Each exterior angle is equal to " +
+ rounded +
+ eachExterior +
+ "˚.";
+ } else {
+ msg =
+ "This irregular polygon with " +
+ sides +
+ " sides has " +
+ totalInterior +
+ "˚ in the interior.";
+ }
+ }
+ document.getElementById("out").style.display = "block";
+ document.getElementById("outText").innerHTML = msg;
+}
+\ No newline at end of file
diff --git a/sizecalc/sizecalc.js b/sizecalc/sizecalc.js
@@ -1,73 +0,0 @@
-var type;
-
-function show(elements) {
- "use strict";
- for (var a = 0; a < elements.length; a++) {
- elements[a].style.display = "inline";
- }
-}
-
-function hide(elements) {
- "use strict";
- for (var a = 0; a < elements.length; a++) {
- elements[a].style.display = "none";
- }
-}
-
-function reset(elements) {
- "use strict";
- for (var a = 0; a < elements.length; a++) {
- elements[a].value = "";
- }
-}
-
-function setUp(selection) {
- "use strict";
- type = selection;
- document.getElementById("sizeIn").style.display = "block";
- hide(document.getElementsByClassName("ins"));
- reset(document.getElementsByClassName("numinput"));
- if (type === "a") {
- show(document.getElementsByClassName("a"));
- } else if (type === "D") {
- show(document.getElementsByClassName("D"));
- } else {
- show(document.getElementsByClassName("d"));
- }
- document.getElementById("out").style.display = "none";
-}
-
-function angularSize(size, distance) {
- "use strict";
- return (180 * size) / (3.14 * distance);
-}
-
-function realSize(angle, distance) {
- "use strict";
- return (angle * 3.14 * distance) / 180;
-}
-
-function calcDistance(size, angle) {
- "use strict";
- return (180 * size) / (3.14 * angle);
-}
-
-function actionManager(angle, size, distance) {
- "use strict";
- if (type === "a") {
- document.getElementById("out").style.display = "block";
- document.getElementById("numOut").innerHTML = "𝛼 = " + angularSize(size, distance);
- } else if (type === "D") {
- document.getElementById("out").style.display = "block";
- document.getElementById("numOut").innerHTML = "D = " + realSize(angle, distance);
- } else {
- document.getElementById("out").style.display = "block";
- document.getElementById("numOut").innerHTML = "d = " + calcDistance(size, angle);
- }
-}
-/*
-Test values:
-𝛼 = 0.266513692671216
-D = 432168.6
-d = 92955810
-*/
-\ No newline at end of file