Created
July 27, 2017 22:20
-
-
Save Cristo86/ef3404ebad7bcf3ee092d8bb30a4eaa1 to your computer and use it in GitHub Desktop.
Returns the point where a plane intersects a given line
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
/** | |
* findLinePlaneIntersectionCoords (to avoid requiring unnecessary instantiation) | |
* Given points p with px py pz and q that define a line, and the plane | |
* of formula ax+by+cz+d = 0, returns the intersection point or null if none. | |
*/ | |
function findLinePlaneIntersectionCoords(px, py, pz, qx, qy, qz, a, b, c, d) { | |
var tDenom = a*(qx-px) + b*(qy-py) + c*(qz-pz); | |
if (tDenom == 0) return null; | |
var t = - ( a*px + b*py + c*pz + d ) / tDenom; | |
return { | |
x: (px+t*(qx-px)), | |
y: (py+t*(qy-py)), | |
z: (pz+t*(qz-pz)) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(ref: https://www.youtube.com/watch?v=qVvvy5hsQwk )