Last active
September 15, 2018 17:21
-
-
Save thelastpenguin/1285c8376fb06d1b0421ac4106baee84 to your computer and use it in GitHub Desktop.
GLua code to compute the intersection of a line with a plane. Used for determining where a player is looking on a 3D2D Screen
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
-- l0 is the origin of the line | |
-- l is the direction of the line expressed as a normal vector (tbd: does it have to be normal? possibly not) | |
-- p0 is the origin of the plane | |
-- n is a vector orthogonal to the surface of the plane expressed as a normal vector (tbd: does it have to be normal? possibly not) | |
function vectorIntersectPlane(l0, l, p0, n) | |
-- we find d by substituting the equation for the line into the equation of the plane and solving for d | |
d = (p0 - l0):Dot(n) / l:Dot(n) -- distance along the line at which the line intersects the plane | |
-- the point of intersection is found by substituting the distance back into the line equation | |
-- p = dl + l0 | |
return d * l + l0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment