简介
如何通过三个点计算一个平面的的方程。
数学相关
A(0,1,0);
B(1,0,0);
C(1,1,0);
$$\vec{AB} = B - A = (1,-1,0)$$
$$\vec{AC} = C - A = (1,0,0)$$
\begin{equation}
\vec{AB} \times \vec{AC} =
\left(
\begin{array}{ccc}
i & j & k\
1 & -1 & 0\
1 & 0 & 0
\end{array}
\right)
=
\left(
\begin{array}{cc}
-1 & 0\
0 & 0
\end{array}
\right)_{i}
- \left(
\begin{array}{cc}
1 & 0\
1 & 0
\end{array}
\right)_{j} - \left(
\begin{array}{cc}
1 & -1\
1 & 0
\end{array}
\right)_{z}
=
(0,0,1) = (a,b,c)
\end{equation} % 注意观察计算某个向量就把某一列遮住,然后即可计算
得到
a(x - x_{0}) + b(y - y_{0}) + c(z- z_{0}) = 0
==>
0(x - x_{0}) + 0(y - y_{0}) + 1(z- z_{0}) = 0
==> 带入 A 点的坐标
z = 0 即标准答案~~
C++ 实现
void SimpleMesh::computeABCD(Mesh::Point &point1, Mesh::Point &point2, Mesh::Point &point3, double& a, double& b, double & c, double &d)
{Mesh::Normal vecP1P2 = point2 - point1;Mesh::Normal vecP1P3 = point3 - point1;Mesh::Normal vecNormal = vecP1P2 % vecP1P3;double length = getDis(vecNormal, vecNormal);a = vecNormal[0] / length;b = vecNormal[1] / length;c = vecNormal[2] / length;// 带入point1 //a * ( x - point1[0] ) + b * (y - point1[1]) + c * (z - point1[2]) = 0d = a * (-1) * point1[0] + b * (-1) * point1[1] + c * (-1) * point1[2];
}