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
### Angle Conversions ### | |
convertAngle = | |
degree: {} | |
gradian: {} | |
milliradian: {} | |
radian: {} | |
arcSecond: {} | |
arcMinute: {} |
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
# Requirement: https://gist.github.com/jgphilpott/092c0f3e1bcfa75f543e8485b9b23e7d | |
# In all triangles the sum of the angles is always equal to 180 degrees. | |
angle$angles = (a = null, b = null) -> | |
if a + b < 180 | |
return 180 - a - b | |
else |
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
# Requirement: https://gist.github.com/jgphilpott/12783015d68e056e54252355d75b41a9 | |
format = (number, category = null, unit = null, floatMax = 2, floatMin = 0, lang = "en-US") -> | |
if (typeof number == "number") | |
switch category | |
when "angle" |
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
byteSize = (obj) -> | |
return JSON.stringify(obj).length |
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
# Find the best-fit curve for an nth order polynomial. | |
# Credit: https://stackoverflow.com/a/28301054/1544937 | |
# Requirement: https://github.com/sloisel/numeric/blob/master/src/numeric.js | |
polyfit = (xArray, yArray, order) -> | |
matrix = [] | |
if xArray.length <= order | |
console.warn "Warning: Polyfit may be poorly conditioned." |
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
# Find the tangent of any polynomial function at x. | |
findTangent = (x, coefficients) -> | |
slope = 0 | |
intercept = coefficients[0] | |
for index in [1 ... coefficients.length] | |
slope += coefficients[index] * index * Math.pow x, index - 1 | |
intercept += coefficients[index] * Math.pow x, index |
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
# Find the tangent of any polynomial function at x. | |
def find_tangent(x, coefficients): | |
slope = 0 | |
intercept = coefficients[0] | |
for i, coefficient in enumerate(coefficients): | |
if i != 0: |
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
# Info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty | |
# Info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array | |
# Source: https://gist.github.com/jgphilpott/a1367ca419ac2807ed4340d69356b7f1 | |
Object.defineProperty Array.prototype, "first", | |
value: -> | |
this.at 0 |
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
findRoots = (y = 0, coefficients = []) -> | |
switch coefficients.length | |
when 0 | |
return null | |
when 1 |
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
### Length Conversions ### | |
convertLength = | |
nanometer: {} | |
micrometer: {} | |
millimeter: {} | |
centimeter: {} | |
decimeter: {} | |
meter: {} |