基本計算¶
ベクトル¶
\[
\vec{p} =
\begin{pmatrix}
p_x \\
p_y \\
p_z
\end{pmatrix}
\]
Mapray では mapray.GeoMath.createVector3() を用いてベクトルを生成します。
const p = mapray.GeoMath.createVector3();
// p = [px, py, pz]
行列¶
\[
T =
\begin{pmatrix}
m_{00} & m_{01} & m_{02} & m_{03} \\
m_{10} & m_{11} & m_{12} & m_{13} \\
m_{20} & m_{21} & m_{22} & m_{23} \\
m_{30} & m_{31} & m_{32} & m_{33}
\end{pmatrix}
\]
Mapray では mapray.GeoMath.createMatrix() を用いて行列を生成します。
const m = mapray.GeoMath.createMatrix([
m00, m10, m20, m30,
m01, m11, m21, m31,
m02, m12, m22, m32,
m03, m13, m23, m33
]);
// m = [m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33]
Note
列優先である点にご注意ください。 特に、上記のように並べて記述した場合、数式で書いた場合に対して行と列が入れ替わります。
平行移動行列¶
\[
\mathrm{Trans}(\vec{t}) =
\begin{pmatrix}
1 & 0 & 0 & t_x \\
0 & 1 & 0 & t_y \\
0 & 0 & 1 & t_z \\
0 & 0 & 0 & 1
\end{pmatrix}
\]
拡大行列¶
\[
\mathrm{Scale}(\vec{s}) =
\begin{pmatrix}
s_x & 0 & 0 & 0 \\
0 & s_y & 0 & 0 \\
0 & 0 & s_z & 0 \\
0 & 0 & 0 & 1
\end{pmatrix}
\]
回転行列¶
\(+x\) 軸側から原点を見て \(\theta\) 半時計回りする回転行列。
\[
\mathrm{Rot_x}(\theta) =
\begin{pmatrix}
1 & 0 & 0 & 0 \\
0 & \cos \theta & -\sin \theta & 0 \\
0 & \sin \theta & \cos \theta & 0 \\
0 & 0 & 0 & 1
\end{pmatrix}
\]
\(+y\) 軸側から原点を見て \(\theta\) 半時計回りする回転行列。
\[
\mathrm{Rot_y}(\theta) =
\begin{pmatrix}
\cos \theta & 0 & \sin \theta & 0 \\
0 & 1 & 0 & 0 \\
-\sin \theta & 0 & \cos \theta & 0 \\
0 & 0 & 0 & 1
\end{pmatrix}
\]
\(+z\) 軸側から原点を見て \(\theta\) 半時計回りする回転行列。
\[
\mathrm{Rot_z}(\theta) =
\begin{pmatrix}
\cos \theta & -\sin \theta & 0 & 0 \\
\sin \theta & \cos \theta & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1
\end{pmatrix}
\]
mapray.GeoMath.rotation_matrix() を用いて回転行列を生成することが出来ます。
const angle = 30;
const r_x = mapray.GeoMath.rotation_matrix([1, 0, 0], angle, mapray.GeoMath.createMatrix());
const r_y = mapray.GeoMath.rotation_matrix([0, 1, 0], angle, mapray.GeoMath.createMatrix());
const r_z = mapray.GeoMath.rotation_matrix([0, 0, 1], angle, mapray.GeoMath.createMatrix());
行列による座標値の変換¶
\[
\vec{p_t} = T \vec{p}
\]
行列 \(T\) の性質により計算方法が異なります。
行列がアフィン変換の場合¶
1 2 3 4 | |
行列がアフィン変換以外の場合¶
行列がアフィン変換でない場合は直接必要な値を計算をします。
逆行列¶
\[
T_2 = T^{-1}
\]
1 2 3 | |