関数triangle_outerCircle マニュアル

(The documentation of function triangle_outerCircle)

Last Update: 2023/7/6


◆機能・用途(Purpose)

2次元平面上の三角形の外接円を求める。
Determine the circumscribed circle of a given triangle on a 2-D plane.


◆形式(Format)

#include <geometry.h>
inline void triangle_outerCircle
(const double x1,const double y1,
 const double x2,const double y2,
 const double x3,const double y3,
 double ∗xc,double ∗yc,double ∗r)


◆引数(Arguments)

x1 三角形の1つ目の頂点の\(x\)座標。
The \(x\)-coordinate of the 1st vertex of the triangle.
y1 三角形の1つ目の頂点の\(y\)座標。
The \(y\)-coordinate of the 1st vertex of the triangle.
x2 三角形の2つ目の頂点の\(x\)座標。
The \(x\)-coordinate of the 2nd vertex of the triangle.
y2 三角形の2つ目の頂点の\(y\)座標。
The \(y\)-coordinate of the 2nd vertex of the triangle.
x3 三角形の3つ目の頂点の\(x\)座標。
The \(x\)-coordinate of the 3rd vertex of the triangle.
y2 三角形の3つ目の頂点の\(y\)座標。
The \(y\)-coordinate of the 3rd vertex of the triangle.
x3 三角形の3つ目の頂点の\(x\)座標。
The \(x\)-coordinate of the 3rd vertex of the triangle.
xc 外接円の中心点の\(x\)座標の代入先。 宣言しただけのdouble型変数に&を付けて与える。
Memory into which the \(x\)-coordinate of the center of the circumscribed circle is to be inserted. Give an empty double-type variable with &.
yc 外接円の中心点の\(y\)座標の代入先。 宣言しただけのdouble型変数に&を付けて与える。
Memory into which the \(y\)-coordinate of the center of the circumscribed circle is to be inserted. Give an empty double-type variable with &.
r 外接円の半径の代入先。 宣言しただけのdouble型変数に&を付けて与える。
Memory into which the radius of the circumscribed circle is to be inserted. Give an empty double-type variable with &.


◆使用例(Example)

double xc,yc,r;
triangle_outerCircle(1.2,3.4,-5.6,7.8,9.0,-1.2,&xc,&yc,&r);


◆計算式(Formula)

三角形の3つの頂点の座標を\((x_1,y_1)\), \((x_2,y_2)\), \((x_3,y_3)\)、 外接円の中心点の座標を\((x_c,y_c)\)、半径を\(r\)とする。 3つの頂点が外接円上に位置する条件から \[\begin{equation} (x_1-x_c)^2+(y_1-y_c)^2=r^2 \label{eq.vertex1} \end{equation}\] \[\begin{equation} (x_2-x_c)^2+(y_2-y_c)^2=r^2 \label{eq.vertex2} \end{equation}\] \[\begin{equation} (x_3-x_c)^2+(y_3-y_c)^2=r^2 \label{eq.vertex3} \end{equation}\] である。
Let \((x_1,y_1)\), \((x_2,y_2)\), and \((x_3,y_3)\) be the coordinates of the three convexes of the triangle, \((x_c,y_c)\) be the coordinate of the center of the circumscribed circle, and \(r\) be the radius of the circle. The three convexes must be on the circumscribed circle; this requirement gives Eqs. (\ref{eq.vertex1}-\ref{eq.vertex3}).

(\ref{eq.vertex1}-\ref{eq.vertex3})の式の左辺を展開して \(x_c^2\), \(y_c^2\)を右辺に移項すると以下のようになる。 \[\begin{equation} x_1^2+y_1^2-2x_1x_c-2y_1y_c=r^2-x_c^2-y_c^2 \label{eq.vertex1.expand} \end{equation}\] \[\begin{equation} x_2^2+y_2^2-2x_2x_c-2y_2y_c=r^2-x_c^2-y_c^2 \label{eq.vertex2.expand} \end{equation}\] \[\begin{equation} x_3^2+y_3^2-2x_3x_c-2y_3y_c=r^2-x_c^2-y_c^2 \label{eq.vertex3.expand} \end{equation}\] (\ref{eq.vertex1.expand})(\ref{eq.vertex2.expand})式より \[\begin{equation} x_1^2+y_1^2-2x_1x_c-2y_1y_c=x_2^2+y_2^2-2x_2x_c-2y_2y_c \label{eq.vertex12} \end{equation}\] が得られ、変形して \[\begin{equation} 2(x_2-x_1)x_c+2(y_2-y_1)y_c=x_2^2-x_1^2+y_2^2-y_1^2 \label{eq.vertex12.arrange} \end{equation}\] を得る。同様にして (\ref{eq.vertex1.expand})(\ref{eq.vertex3.expand})式から \[\begin{equation} 2(x_3-x_1)x_c+2(y_3-y_1)y_c=x_3^2-x_1^2+y_3^2-y_1^2 \label{eq.vertex13.arrange} \end{equation}\] も得られ、 (\ref{eq.vertex12.arrange})(\ref{eq.vertex13.arrange})式は まとめて行列形式で \[\begin{equation} \begin{pmatrix} x_2-x_1 & y_2-y_1 \\ x_3-x_1 & y_3-y_1 \end{pmatrix} \begin{pmatrix} 2x_c \\ 2y_c \end{pmatrix} = \begin{pmatrix} x_2^2-x_1^2+y_2^2-y_1^2 \\ x_3^2-x_1^2+y_3^2-y_1^2 \end{pmatrix} \label{eq.xcyc.matrix} \end{equation}\] と書ける。
Expanding the left hand sides of Eqs. (\ref{eq.vertex1}-\ref{eq.vertex3}) and moving \(x_c^2\) and \(y_c^2\) to the right hand side results in Eqs. (\ref{eq.vertex1.expand}-\ref{eq.vertex3.expand}). From Eqs. (\ref{eq.vertex1.expand}) and (\ref{eq.vertex2.expand}), we obtain (\ref{eq.vertex12}), which can be deformed as (\ref{eq.vertex12.arrange}). In the same way, Eqs. (\ref{eq.vertex1.expand}) and (\ref{eq.vertex3.expand}) give (\ref{eq.vertex13.arrange}). Eqs. (\ref{eq.vertex12.arrange})(\ref{eq.vertex13.arrange}) can be rewritten in a matrix form as (\ref{eq.xcyc.matrix}).

(\ref{eq.xcyc.matrix})式の解はクラメルの公式より \[\begin{equation} 2x_c=\frac{|\myvector{A_x}|}{|\myvector{A}|} \label{eq.xc} \end{equation}\] \[\begin{equation} 2y_c=\frac{|\myvector{A_y}|}{|\myvector{A}|} \label{eq.yc} \end{equation}\] と書ける。ここで \[\begin{equation} \myvector{A}= \begin{pmatrix} x_2-x_1 & y_2-y_1 \\ x_3-x_1 & y_3-y_1 \end{pmatrix} \label{eq.A} \end{equation}\] \[\begin{equation} \myvector{A_x}= \begin{pmatrix} x_2^2-x_1^2+y_2^2-y_1^2 & y_2-y_1 \\ x_3^2-x_1^2+y_3^2-y_1^2 & y_3-y_1 \end{pmatrix} \label{eq.Ax} \end{equation}\] \[\begin{equation} \myvector{A_y}= \begin{pmatrix} x_2-x_1 & x_2^2-x_1^2+y_2^2-y_1^2 \\ x_3-x_1 & x_3^2-x_1^2+y_3^2-y_1^2 \end{pmatrix} \label{eq.Ay} \end{equation}\] とおいた。具体的に計算すると \[\begin{eqnarray} |\myvector{A}| &=& \begin{vmatrix} x_2-x_1 & y_2-y_1 \\ x_3-x_1 & y_3-y_1 \end{vmatrix} \nonumber \\ &=& (x_2-x_1)(y_3-y_1)-(x_3-x_1)(y_2-y_1) \nonumber \\ &=& (x_2y_3-x_2y_1-x_1y_3+x_1y_1)-(x_3y_2-x_3y_1-x_1y_2+x_1y_1) \nonumber \\ &=& (x_1y_2-x_2y_1)+(x_2y_3-x_3y_2)+(x_3y_1-x_1y_3) \label{eq.A.explicit} \end{eqnarray}\] \[\begin{eqnarray} |\myvector{A_x}| &=& \begin{vmatrix} x_2^2-x_1^2+y_2^2-y_1^2 & y_2-y_1 \\ x_3^2-x_1^2+y_3^2-y_1^2 & y_3-y_1 \end{vmatrix} \nonumber \\ &=& (x_2^2-x_1^2+y_2^2-y_1^2)(y_3-y_1) -(x_3^2-x_1^2+y_3^2-y_1^2)(y_2-y_1) \nonumber \\ &=& (x_2^2-x_1^2)(y_3-y_1)-(x_3^2-x_1^2)(y_2-y_1) \nonumber \\ & & +(y_2^2-y_1^2)(y_3-y_1)-(y_3^2-y_1^2)(y_2-y_1) \nonumber \\ &=& (x_2^2y_3-x_2^2y_1-x_1^2y_3+x_1^2y_1) -(x_3^2y_2-x_3^2y_1-x_1^2y_2+x_1^2y_1) \nonumber \\ & & +(y_2+y_1)(y_2-y_1)(y_3-y_1)-(y_3+y_1)(y_3-y_1)(y_2-y_1) \nonumber \\ &=& (x_1^2y_2-x_2^2y_1) +(x_2^2y_3-x_3^2y_2) +(x_3^2y_1-x_1^2y_3) \nonumber \\ & & +(y_2-y_3)(y_2-y_1)(y_3-y_1) \nonumber \\ &=& (x_1^2y_2-x_2^2y_1) +(x_2^2y_3-x_3^2y_2) +(x_3^2y_1-x_1^2y_3) \nonumber \\ & & -(y_1-y_2)(y_2-y_3)(y_3-y_1) \label{eq.Ax.explicit} \end{eqnarray}\] \[\begin{eqnarray} |\myvector{A_y}| &=& \begin{vmatrix} x_2-x_1 & x_2^2-x_1^2+y_2^2-y_1^2 \\ x_3-x_1 & x_3^2-x_1^2+y_3^2-y_1^2 \end{vmatrix} \nonumber \\ &=& (x_2-x_1)(x_3^2-x_1^2+y_3^2-y_1^2) -(x_3-x_1)(x_2^2-x_1^2+y_2^2-y_1^2) \nonumber \\ &=& (x_2-x_1)(x_3^2-x_1^2)-(x_3-x_1)(x_2^2-x_1^2) \nonumber \\ & & +(x_2-x_1)(y_3^2-y_1^2)-(x_3-x_1)(y_2^2-y_1^2) \nonumber \\ &=& (x_2-x_1)(x_3-x_1)(x_3+x_1)-(x_3-x_1)(x_2-x_1)(x_2+x_1) \nonumber \\ & & +(x_2y_3^2-x_2y_1^2-x_1y_3^2+x_1y_1^2) -(x_3y_2^2-x_3y_1^2-x_1y_2^2+x_1y_1^2) \nonumber \\ &=& (x_2-x_1)(x_3-x_1)(x_3-x_2) \nonumber \\ & & +(x_1y_2^2-x_2y_1^2) +(x_2y_3^2-x_3y_2^2) +(x_3y_1^2-x_1y_3^2) \nonumber \\ &=& (x_1-x_2)(x_2-x_3)(x_3-x_1) \nonumber \\ & & +(x_1y_2^2-x_2y_1^2) +(x_2y_3^2-x_3y_2^2) +(x_3y_1^2-x_1y_3^2) \label{eq.Ay.explicit} \end{eqnarray}\] である。 (\ref{eq.A.explicit}-\ref{eq.Ay.explicit})を (\ref{eq.xc})(\ref{eq.yc})に代入し、 更にその結果を(\ref{eq.vertex1}-\ref{eq.vertex3})のいずれかに代入すれば \(x_c\), \(y_c\), \(r\)が求まる。
The solution of Eq. (\ref{eq.xcyc.matrix}) can be computed using the Cramer's formula as Eqs. (\ref{eq.xc}) and (\ref{eq.yc}), where the matrices \(\myvector{A}\), \(\myvector{A_x}\), and \(\myvector{A_y}\) are defined by Eqs. (\ref{eq.A}-\ref{eq.Ay}). Explicit formulas are (\ref{eq.A.explicit}-\ref{eq.Ay.explicit}). Inserting them into Eqs. (\ref{eq.xc}) and (\ref{eq.yc}) and further inserting the results into one of Eqs. (\ref{eq.vertex1}-\ref{eq.vertex3}) yields all of \(x_c\), \(y_c\), and \(r\).