Skip to content

Instantly share code, notes, and snippets.

@neysidev
Created November 28, 2023 07:27
Show Gist options
  • Select an option

  • Save neysidev/66f9347468cbc56fdc242491f72cf8b3 to your computer and use it in GitHub Desktop.

Select an option

Save neysidev/66f9347468cbc56fdc242491f72cf8b3 to your computer and use it in GitHub Desktop.
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