関数judge_4points_on_plane マニュアル

(The documentation of function judge_4points_on_plane)

Last Update: 2023/12/21


◆機能・用途(Purpose)

3次元空間内の4地点が1つの平面上に乗るか否かを判別する。
Identify whether four points in a 3-D space are on a flat plane.


◆形式(Format)

#include <geometry.h>
inline _Bool judge_4points_on_plane
(const double ∗P0,const double ∗P1, const double ∗P2,const double ∗P3);


◆引数(Arguments)

P0 1つ目の点の座標。 \(x\), \(y\), \(z\)座標を並べた3要素から成る配列として与える。
The coordinate of the 1st point, given as an array of 3-components that represent the \(x\)-, \(y\)-, and \(z\)-coordinates.
P1 2つ目の点の座標(P0と同じ書式)。P0とは異なっていなければならない。
The coordinate of the 2nd point (same format as above), which must be different from P0.
P2 3つ目の点の座標(同上)。P0, P1とは異なっていなければならない。
The coordinate of the 3rd point (same format as above), which must be different from P0 and P1.
P3 4つ目の点の座標(同上)。P0, P1, P2とは異なっていなければならない。
The coordinate of the 4th point (same format as above), which must be different from P0, P1, and P2.


◆戻り値(Return value)

4点が1つの平面上に位置する場合はtrue、そうでなければfalse。
Return true if the four points are on a flat plane, false otherwise.


◆使用例(Example)

double P0[]={1.2,3.4,5.6};
double P1[]={7.8,9.1,2.3};
double P2[]={1.23,4.56,7.89};
double P3[]={-9.8,-7.6,-5.4};
_Bool on_olane_flag=judge_4points_on_plane(P0,P1,P2,P3);


◆アルゴリズム(The algorithm)

4地点を\(P_0\), \(P_1\), \(P_2\), \(P_3\)とし、 \(\myvector{V_1}\equiv \overrightarrow{P_0P_1}\)、 \(\myvector{V_2}\equiv \overrightarrow{P_0P_2}\)、 \(\myvector{V_3}\equiv \overrightarrow{P_0P_3}\) とおく。 ベクトル積\(\myvector{V_1}\times\myvector{V_2}\)は \(\myvector{V_1}\), \(\myvector{V_2}\)が張る平面 (3点\(P_0\), \(P_1\), \(P_2\)を通る平面)に直交する。 もしこのベクトル積と\(\myvector{V_3}\)との内積が0になったなら、 \(\myvector{V_3}\)は\(\myvector{V_1}\times\myvector{V_2}\)に直交し、 したがって\(\myvector{V_3}\)は \(\myvector{V_1}\), \(\myvector{V_2}\)が張る平面上にあることになる。 この考察より、3つのベクトル \(\myvector{V_1}\), \(\myvector{V_2}\), \(\myvector{V_3}\) が1つの平面に乗る条件は
\[\begin{equation} (\myvector{V_1}\times\myvector{V_2})\cdot\myvector{V_3}=0 \label{eq.condition} \end{equation}\] と書ける。
Let \(P_0\), \(P_1\), \(P_2\), and \(P_3\) be the four points, and let vectors be defined as \(\myvector{V_1}\equiv \overrightarrow{P_0P_1}\), \(\myvector{V_2}\equiv \overrightarrow{P_0P_2}\), and \(\myvector{V_3}\equiv \overrightarrow{P_0P_3}\). A vector product \(\myvector{V_1}\times\myvector{V_2}\) is orthogonal to a plane made of \(\myvector{V_1}\) and \(\myvector{V_2}\), that is, a plane that passes through the points \(P_0\), \(P_1\), and \(P_2\). If an inner product between this vector product and \(\myvector{V_3}\) is zero, then \(\myvector{V_3}\) is orthogonal to \(\myvector{V_1}\times\myvector{V_2}\) and thus is on the plane made of \(\myvector{V_1}\) and \(\myvector{V_2}\). This discussion leads to a conclusion that the three vectors are on a flat plane if Eq. (\ref{eq.condition}) holds.

数値計算において厳密に0.0が得られることは稀である。 そこで(\ref{eq.condition})式の代わりに \[\begin{equation} |(\myvector{V_1}\times\myvector{V_2})\cdot\myvector{V_3}| \ll |\myvector{V_1}| |\myvector{V_2}| |\myvector{V_3}| \label{eq.condition.practical} \end{equation}\] という条件が成り立つか否かをチェックする。 「十分に小さい」(\(\ll\))の判断基準としては定数マクロ ZERO_THRESHOLD を用いる。
It is rare that 0.0 is exactly obtained in a numerical calculation. Therefore, Eq. (\ref{eq.condition.practical}) is used instead of Eq. (\ref{eq.condition}), where the “substantially small” \(\ll\) is determined based on a constant macro ZERO_THRESHOLD.