Skip to content

Instantly share code, notes, and snippets.

View JudeOsborn's full-sized avatar

Jude Osborn JudeOsborn

  • Google
  • Sydney, Australia
View GitHub Profile
@JudeOsborn
JudeOsborn / angleFromPoints.js
Created September 16, 2012 23:40
Get the angle from two coordinates.
function angleFromPoints(p1, p2) {
return Math.atan2(p2.y - p1.y, p2.x - p1.x);
}
@JudeOsborn
JudeOsborn / lineDistance.js
Created September 16, 2012 23:40
Calculate the distance between two coordinates
function lineDistance(p1, p2) {
var xs = 0;
var ys = 0;
xs = p2.x - p1.x;
xs = xs * xs;
ys = p2.y - p1.y;
ys = ys * ys;
@JudeOsborn
JudeOsborn / circlePoint.js
Created September 16, 2012 23:42
Find the point on a the circumference of a circle with a given angle, radius and center coordinates.
function circPoint(angle, center, radius) {
return {
x: center.x + radius * Math.cos(degreesToRadians(angle)),
y: center.y + radius * Math.sin(degreesToRadians(angle))
};
}
@JudeOsborn
JudeOsborn / degreesRadians.js
Created September 16, 2012 23:42
Convert between degrees and radians
/**
* Converts degrees to radians.
*
* @param degrees
*/
function degreesToRadians(degrees) {
return degrees * Math.PI / 180;
}
/**