#TikZで3次元プロットをする
$\def\fraction(#1/#2){\frac{#1}{#2}}$ $\def\bunsu(#1/#2){\frac{,#1,}{,#2,}}$ $\def\DIS{\displaystyle}$ $\def\unisq{\mathrm{cm^2}}$ $\def\unicube{\mathrm{cm^3}}$ $\def\defsym{\overset{\rm def}{=}}$ $\def\subsym{\overleftarrow{\rm sub}}$
パッケージ
\usepackage{tikz-3dplot}
描画
カメラアングルを天頂角$\theta$(90-緯度)と方位角$\phi$で書くことができます。
\begin{tikzpicture}
の前に,\tdplotsetmaincoords{天頂角}{方位角}
を書きます。ただし,方位角$\phi$は$y$軸負の方向から取ります。角度は度数法で書きます。数値の積の形,分数の形でも書くことができます。
\begin{tikzpicture}
のオプションにtdplot_main_coords
を入れます。
\tdplotsetmaincoords{#実数1}{#実数2}
\begin{tikzpicture}[tdplot_main_coords]
.
.
.
\end{tikzpicture}
\tdplotsetmaincoords{#実数1}{#実数2}
#実数1
, #実数2
は3次元空間内のカメラの位置を表現しています。
#実数1
はz軸から傾いた角度,#実数2
はz軸まわりに回転した角度を意味している。ただし,#実数2
はy軸からx軸への回転角(時計回り)になるため,注意が必要。
例
\tdplotsetmaincoords{60}{125}
z軸から60°,z軸まわりに125°回転させたという意味。
\tdplotsetmaincoords{0}{0}
x-y平面が,横軸x・縦軸yの形で見える(通常通り)。
座標の記述
座標は3つの数値の組(#実数1,#実数2,#実数3)
で記述します。(#実数1,#実数2)
と記述されているものは,(#実数1,#実数2,0)
と解釈されると思う。
重なり順
描画される図形の重なる順番は,後の行ほど手前になる。3次元的な位置関係の重なり順は意味をもたない。
クリップ (clip)
以前,カメラの天頂角,方位角を使って座標を回転させて,いつも一定の形のclipをしていましたが,tikz-3dplot
に備わった機能がありました。
tdplot_screen_coords
オプションにtdplot_screen_coords
と書いておくと,デフォルトのカメラアングルの座標を書くことができます。切り抜きのコマンドに使用する場合は,
\clip [tdplot_screen_coords] (-4,-4,0) rectangle (4,4,0);
と書くと,正面を向いている長方形になります。
カメラ位置の回転角(没)
\tikzmath
$\phi \defsym 0$
$\delta \defsym $ 0
$\theta \defsym 90 - \delta$
$\delta $:z軸からの角度 緯度の反対の取り方
%3次元プロットの記述
\tdplotsetmaincoords{ $\delta$ }{ $\phi$ }
\begin{tikzpicture}[tdplot_main_coords]
...
\end{tikzpicture}
3次元プロットを使用した場合,\clip
で指定した座標が3次元の座標として指定されるので,角度がついてしまいます。
カメラの向きに合わせてクリップしたい場合もあります。そんな場合は,一度座標を指定して,それを回転させてからクリップで指定しましょう。
クリップする座標の変換
初期値の代入
\tikzmath
\begin{pmatrix}
x\\
y\\
z
\end{pmatrix} \subsym
\begin{pmatrix}
C_x^{max}\\
0\\
C_z^{max}
\end{pmatrix}
yz平面の回転
\tikzmath
\begin{pmatrix}
x\\
y\\
z
\end{pmatrix} \subsym
\begin{pmatrix}
x\\
\cos (-\theta) y - \sin (-\theta) z\\
\sin (-\theta) y + \cos (-\theta) z
\end{pmatrix}
xy平面の回転
\tikzmath
\begin{pmatrix}
x\\
y\\
z
\end{pmatrix} \subsym
\begin{pmatrix}
\cos (\phi) x - \sin (\phi) y\\
\sin (\phi) x + \cos (\phi) y\\
z
\end{pmatrix}