How to do ray plane intersection?

后端 未结 4 471
旧巷少年郎
旧巷少年郎 2020-12-08 21:26

How do I calculate the intersection between a ray and a plane?

Code

This produces the wrong results.

float denom = normal.dot(ray.direction         


        
4条回答
  •  孤街浪徒
    2020-12-08 22:03

    First consider the math of the ray-plane intersection:

    In general one intersects the parametric form of the ray, with the implicit form of the geometry.

    So given a ray of the form x = a * t + a0, y = b * t + b0, z = c * t + c0;

    and a plane of the form: A x * B y * C z + D = 0;

    now substitute the x, y and z ray equations into the plane equation and you will get a polynomial in t. you then solve that polynomial for the real values of t. With those values of t you can back substitute into the ray equation to get the real values of x, y and z. Here it is in Maxima:

    enter image description here

    Note that the answer looks like the quotient of two dot products! The normal to a plane is the first three coefficients of the plane equation A, B, and C. You still need D to uniquely determine the plane. Then you code that up in the language of your choice like so:

    Point3D intersectRayPlane(Ray ray, Plane plane)
    {
        Point3D point3D;
    
        //  Do the dot products and find t > epsilon that provides intersection.
    
    
        return (point3D);
    }
    

提交回复
热议问题