Created
March 31, 2020 21:28
-
-
Save bit-hack/fb08b5338d83888475b77e1ca5fcf9db to your computer and use it in GitHub Desktop.
point on line solver given one component
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
// for the line from [x0,y0] -> [x1,y1] | |
// given y solve for sx (point on line) | |
// given x solve for sy (point on line) | |
const float dx = x1 - x0; | |
const float dy = y1 - y0; | |
const float sx = x0 + (y*dx - y0*dx) / dy; | |
const float sy = y0 + (x*dy - x0*dy) / dx; | |
// or | |
const float sx = x0 + (y - y0) * (dx/dy); | |
const float sy = y0 + (x - x0) * (dy/dx); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment