Hei. Are making a game and are looking for a ray intersection onto a square or a rectangle only in 3D space. Have search the web and found many solutions but nothing i can u
Create a vector equation for a line in R3, then solve for the intersection of that line in the plane of the rectangle that you are testing it against. After that, it's simple enough to test if that point of solution lies within the bounds.
the parameter t of the solution can be found with:
t = (a * (x0 - rx) + b * (y0 - ry) + c * (x0 - rz)) / (a * vx + b * vy + c * vz)
where:
a(x - x0) + b(y - y0) + c(z - z0) = 0
is the equation of the plane that your rectangle lies on
and:
=
is the vector equation of the line in question.
note that:
is the initial point of the vector equation, and
is the direction vector of the above equation
After that, plugging the parameter t into your vector equation will give you the point to test for distance.
