How to do ray plane intersection?

后端 未结 4 467
旧巷少年郎
旧巷少年郎 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 21:57

    implementation of vwvan's answer

    Vector3 Intersect(Vector3 planeP, Vector3 planeN, Vector3 rayP, Vector3 rayD)
    {
        var d = Vector3.Dot(planeP, -planeN);
        var t = -(d + rayP.z * planeN.z + rayP.y * planeN.y + rayP.x * planeN.x) / (rayD.z * planeN.z + rayD.y * planeN.y + rayD.x * planeN.x);
        return rayP + t * rayD;
    }
    

提交回复
热议问题