Created
December 11, 2017 12:55
-
-
Save hpohlmeyer/40bdfc015942daee0a739fb1c3802462 to your computer and use it in GitHub Desktop.
Get a point on a line, defined by two other points
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
// Line Interpolation | |
function createLineInterpolationFunction(p1, p2) { | |
const slope = (p2.y - p1.y) / (p2.x - p1.x); | |
const yIntercept = p1.y - (slope * p1.x); | |
return (x) => slope * x + yIntercept; | |
} | |
// Example | |
const getY = createLineInterpolationFunction({ x: 200, y: 20}, { x: 1440, y: 60 }); | |
const point = { x: 100, y: getY(100) }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment