Created
December 12, 2013 18:49
-
-
Save jesgundy/7933287 to your computer and use it in GitHub Desktop.
Greg's Handy formulas
This file contains hidden or 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
Radians of a circle: Math.PI * 2; | |
Radians to degrees: radians * 180 / Math.PI; | |
Degrees to radians: degrees * Math.PI / 180; | |
Midpoint interpolation: minValue + (maxValue - minValue) * percent | |
Angle (radians) between two points: Math.atan2(end.y-start.y, end.x-start.x) | |
distance between two points: pythagorean theorem... | |
function distance(start, end) { | |
var a = start.x-end.x, b = start.y-end.y; | |
return Math.sqrt(a*a + b*b); | |
} | |
X-coordinate offset at angle: offset * Math.sin(angleRadians); | |
Y-coordinate offset at angle: offset * Math.cos(angleRadians); | |
Offset from origin at angle: | |
function radialOffset(origin, offset, angleRadians) { | |
return { | |
x: origin.x + offset * Math.sin(angleRadians), | |
y: origin.y + offset * Math.cos(angleRadians) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment