Created
December 14, 2016 10:21
-
-
Save vaseker/ed813892cc90c1c40339cece3b0366fe to your computer and use it in GitHub Desktop.
School geometry
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
/* 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