点到平面距离公式
distance = Ax + By + Cz + D; //点P(x,y,z),平面的法向量n=(A,B,C),D是距原点的距离.
其中n = (A, B, C)是平面的法向量,D是将平面平移到坐标原点所需距离(所以D=0时,平面过原点)
- 当
d < 0
— 点在平面法向反方向所指的区域; - 当
d > 0
— 点在平面法向所指的区域; - 当
d = 0
— 点在平面上。
使用函数表示如下:
bool isPointAboveThePlane(const Vector3& point, const Vector4& plane) {return (plane.x*point.x + plane.y*point.y + plane.z*point.z + plane.w >= 0);
}
推导过程
其中,求向量的模长,求法为:给定一个向量V(x, y, z),则|V| = sqrt(x * x + y * y + z * z)。
引擎中的实现
Real Plane::getDistance (const Vector3& rkPoint) const
{return normal.dotProduct(rkPoint) + d;
}
编者:艾孜尔江·艾尔斯兰