Skip to content

Instantly share code, notes, and snippets.

@Cristo86
Created July 27, 2017 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cristo86/ef3404ebad7bcf3ee092d8bb30a4eaa1 to your computer and use it in GitHub Desktop.
Save Cristo86/ef3404ebad7bcf3ee092d8bb30a4eaa1 to your computer and use it in GitHub Desktop.
Returns the point where a plane intersects a given line
/**
* 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))
};
}
@Cristo86
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment