Skip to content

Instantly share code, notes, and snippets.

@vaseker
Created December 14, 2016 10:21
Show Gist options
  • Save vaseker/ed813892cc90c1c40339cece3b0366fe to your computer and use it in GitHub Desktop.
Save vaseker/ed813892cc90c1c40339cece3b0366fe to your computer and use it in GitHub Desktop.
School geometry
/* Get equation of line going through 2 points */
function getLine(point0, point1) {
var k = (point1[1] - point0[1]) / (point1[0] - point0[0]);
var b = -k * point0[0] + point0[1];
return {
k: k,
b: b,
y: function (x) { return k * x + b; }
};
}
/* Get equation of perpendicular line crossing in point */
function getPerpendicular(point, line) {
var k = -1 / line.k;
return {
y: function (x) {
return (x - point[0]) * k + point[1];
},
x: function (y) {
return (y - point[1]) / k + point[0];
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment