I'm writing an 3D application. I have to deteminate at which face the user is currently looking (not always axis aligned).
I have the position of each face as four points. I have the line as a vector.
I've looked up that i can calculate the normal of the face and with that the equation(s) of the face. I can also calculate the equation of the line.
If i merge those i am able to calculate the intersection point (on the plane) and then look if that point is on the face. But how do i solve those equations in code?
How can i simply calculate if the line intersects with the face?
Edit: How can i solve these equations using java code?
Equations of Line
x = point.x - dir.x * t
y = point.y - dir.y * t
z = point.z - dir.z * t
Equation of Plane
normal.x * (x - face[0].x) + normal.y * (y - face[0].y) + normal.z * (z - face[0].z) = 0