Skip to content

Instantly share code, notes, and snippets.

@jesgundy
Created December 12, 2013 18:49
Show Gist options
  • Save jesgundy/7933287 to your computer and use it in GitHub Desktop.
Save jesgundy/7933287 to your computer and use it in GitHub Desktop.
Greg's Handy formulas
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