一:代数方式
我们假设它们的交点为P,既然我们有一个平面,那么平面上面的一个点P0和平面的normal(垂直于平面的向量)我们是肯定知道的。
根据3D数学知识,(P-P0) · normal = 0(公式一);(既然垂直,那么它们点乘肯定为0)。
对于这条直线,我们肯定知道直线上面的某一点L0和直线的方向L,那么 P = L0 + dL(公式二),d是距离。
把公式二代入公式一,我们可以得到如下:
(L0 + dL - P0)· normal = 0;---> dL · normal + (L0 - P0) · normal = 0;
这样我们可以求出d值,然后我们就可以通过公式二求出P啦!
附上C#代码:
//point 是直线上面某一点,direct是直线的方向,planeNormal是垂直于平面的向量,planePoint是平面上的任意一点
public static Vector3 GetIntersectWithLineAndPlane(Vector3 point,Vector3 direct,Vector3 planeNormal,Vector3 planePoint)
{
float d = Vector3.Dot (planePoint - point, planeNormal)/Vector3.Dot(direct,planeNormal);
return d * direct.normalized + point;
}
原文链接:
如何求直线与平面的交点(两种方式) - it610.com一:代数方式我们假设它们的交点为P,既然我们有一个平面,那么平面上面的一个点P0和平面的normal(垂直于平面的向量)我们是肯定知道的。根据3D数学知识,(P-P0)·normal=0(公式一);(既然垂直,那么它们点乘肯定为0)。对于这条直线,我们肯定知道直线上面的某一点L0和直线的方向L,那么P=L0+dL(公式二),d是距离。把公式二代入公式一,我们可以得到如下:(L0+dL-P0)·nohttps://www.it610.com/article/1305781798361403392.htmhttps://www.it610.com/article/1305781798361403392.htm