Search code examples
game-enginegame-physicsraytracing

Plane-Ray intersection C#


I have this code for plane-ray intersection: http://pastebin.com/2VuPeZ5r I think I compute t correctly, but I need to return null if there is no intersection. How do I check that?

Thanks


Solution

  • What do you mean by "no intersection"? Any ray will intersect a plane somewhere, except for the degenerate case where the ray is exactly perpendicular to the normal of the plane. To detect that case, test for Vector3.Dot(Norm, ray.Dir) == 0.

    If you want to know if the intersection is in front of or behind the ray origin, test for t > 0.