通过三点计算一个平面 ax+by+cz+d = 0

简介

如何通过三个点计算一个平面的的方程。

数学相关

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) ]

[egin{equation} vec{AB} imes vec{AC} = left( egin{array}{ccc} i & j & k\ 1 & -1 & 0\ 1 & 0 & 0 end{array} ight) ]

=
left(
egin{array}{cc}
-1 & 0
0 & 0
end{array}
ight){i}
+
left(
egin{array}{cc}
1 & 0
1 & 0
end{array}
ight)
{j}
+
left(
egin{array}{cc}
1 & -1
1 & 0
end{array}
ight)_{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]) = 0
	d = a * (-1) * point1[0] + b * (-1) * point1[1] + c * (-1) * point1[2];
}
Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
原文地址:https://www.cnblogs.com/eat-too-much/p/11323541.html