Created
November 28, 2023 07:27
-
-
Save neysidev/66f9347468cbc56fdc242491f72cf8b3 to your computer and use it in GitHub Desktop.
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
| function findLineEquation(point1, point2) { | |
| const slope = (point2.y - point1.y) / (point2.x - point1.x); | |
| const yIntercept = point1.y - slope * point1.x; | |
| return { slope, yIntercept }; | |
| } | |
| function findCorrespondingY(point1, point2, x) { | |
| const lineEquation = findLineEquation(point1, point2); | |
| return lineEquation.slope * x + lineEquation.yIntercept; | |
| } | |
| const point1 = { x: 0, y: 0 }; | |
| const point2 = { x: 100, y: 100 }; | |
| console.log(findCorrespondingY(point1, point2, 50)); // 25 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment