POINT
記事のために作った図のTeXコード(TikZを利用)を,備忘録として残します.
- TikZを使うと,TeX環境で簡単にきれいな図を作成することができる.
- TikZで作成した図(3D)のソースコードを紹介!
- TikZ実例集〜2Dグラフ編 - Notes_JP
ベクトルの回転(3次元)
作成した図:
この図は,以下の記事で使っています:
\begin{figure}[htbp] % 左の図 \begin{minipage}{0.3\hsize} \begin{center} \begin{tikzpicture}[scale=1.5, rotate=0] \begin{axis}[ title={3D Rotation}, view={60}{30}, axis lines=none, ticks=none, xmin=-30, xmax=50, ymin=0-30, ymax=50, zmin=0, zmax=50, ] % \node at(axis cs:0,0,0) [anchor=north]{$\boldsymbol{O}$}; % \draw[-stealth,thick] (axis cs:0,0,0) -- (axis cs:0,0,50); \node at(axis cs:0,0,{50/2}) [anchor=east]{$(\boldsymbol{r}\cdot\boldsymbol{n})\boldsymbol{n}$}; % \draw[-stealth,thick] (axis cs:0,0,0) -- (axis cs:30,0,50); \node at(axis cs:30,0,50) [anchor=north east]{$\boldsymbol{r}$}; \draw[-stealth,thick] (axis cs:0,0,0) -- (axis cs:{30/2},{30*sqrt(3)/2},50); \node at(axis cs:{30/2},{30*sqrt(3)/2},50) [anchor=west]{$\boldsymbol{r^\prime}$}; % \draw[thin,gray] (axis cs:0,0,50) circle (300); \fill[orange, opacity=.5, thin] (axis cs:0,0,50) circle (300); % \draw[-stealth,red,very thick] (axis cs:0,0,50) -- (axis cs:0,0,60); \node at(axis cs:0,0,60) [anchor=north west]{$\boldsymbol{n}$}; % \draw[-stealth,dashed] (axis cs:0,0,50) -- (axis cs:30,0,50); \draw[-stealth,dashed] (axis cs:0,0,50) -- (axis cs:{30/2},{30*sqrt(3)/2},50); \draw [thin,->](axis cs:10,0,50) arc (0:60:100); \node at(axis cs:3,8,50) [anchor=north west]{$\theta$}; \end{axis} \end{tikzpicture} \end{center} \end{minipage} %中央の空間 \begin{minipage}{0.2\hsize} \begin{center} \end{center} \end{minipage} % 右の図 \begin{minipage}{0.3\hsize} \begin{center} \begin{tikzpicture}[scale=2] %円 \draw[thin,gray] (0,0) circle (1); \fill[orange, opacity=.5, thin] (0,0) circle (1); % \draw [thin,->](0:1/4) arc (0:60:1/4); \node at(40:1/4) [anchor=west]{$\theta$}; % ベクトル \draw [very thick,-stealth,dashed](0,0)--(1,0)node [anchor=west]{$\color{red}{\boldsymbol{r}-(\boldsymbol{r}\cdot\boldsymbol{n})\boldsymbol{n}}$}; \draw [very thick,-stealth,dashed](0,0)--(1/2,{sqrt(3)/2})node [anchor=west]{$\left[\color{red}{\boldsymbol{r}-(\boldsymbol{r}\cdot\boldsymbol{n})\boldsymbol{n}}\right]\cos\theta+\left(\color{blue}{\boldsymbol{n}\times\boldsymbol{r}}\right)\sin\theta$}; \draw [very thick,-stealth](0,0)--(0,1)node [anchor=south]{$\color{blue}{\boldsymbol{n}\times\boldsymbol{r}}$}; %直角記号 \draw[thin] (0,0.1) -- (0.1,0.1) -- (0.1,0); \end{tikzpicture} \end{center} \end{minipage} \end{figure}
回転体
TikZ, pgfplotで作成しました.その1
作成した図:
\begin{center} \begin{tikzpicture}[scale=2] \begin{axis}[ title={Rotation of $f(x)$}, colormap/greenyellow, view={30}{30},%15,30 axis lines=center, ticks=none, xmin=0, xmax=2.5, ymin=-40, ymax=60, zmin=-40, zmax=40, xlabel=$x$, ylabel=$y$, zlabel=$z$, every axis x label/.style={ at={(ticklabel* cs:1.05)}, anchor=west, }, every axis y label/.style={ at={(ticklabel* cs:1.05)}, anchor=west, }, every axis z label/.style={ at={(ticklabel* cs:1.05)}, anchor=south, } ] \addplot3[ % mesh, surf, opacity=0.5, shader=faceted, samples=20, domain=0:2,y domain=0:2*pi, z buffer=sort] (x,{(60/(x+2))* cos(deg(y))},{(60/(x+2)) * sin(deg(y))}); % \draw[red, domain=0:pi/4, samples=200]plot(axis cs:0,{10* cos(deg(\x))}, {10* sin(deg(\x))}); \node at(axis cs:0,5,8) [anchor=west]{$\theta$}; % \draw[-stealth,red,thin] (axis cs:0,0,0) -- (axis cs:0,{30*cos(deg(pi/4))},{30*sin(deg(pi/4))}); \draw[dashed,thin] (axis cs:0,{30*cos(deg(pi/4))},0) -- (axis cs:0,{30*cos(deg(pi/4))},{30*sin(deg(pi/4))}); \draw[dashed,thin] (axis cs:0,0,{30*sin(deg(pi/4))}) -- (axis cs:0,{30*cos(deg(pi/4))},{30*sin(deg(pi/4))}); \end{axis} \end{tikzpicture} \end{center}
参考記事:
- PGFplots 3d: Creating a filled solid of revolution - TeX - LaTeX Stack Exchange
- pgfplot: 3D version of a plane and its the gradient vector - TeX - LaTeX Stack Exchange
- tikz pgf - Naming 3D axes in pgfplots - TeX - LaTeX Stack Exchange
- How can I adjust the position of xlabel and ylabel with pgfplots? - TeX - LaTeX Stack Exchange
その2
上の図にいくつか図を追加すると,次のような図も作成できます.
\begin{center} \begin{tikzpicture}[scale=2] \begin{axis}[ title={Rotation of $f(x)$}, colormap/greenyellow, view={30}{30},%15,30 axis lines=center, ticks=none, xmin=0, xmax=2.5, ymin=-40, ymax=60, zmin=-40, zmax=40, xlabel=$x$, ylabel=$y$, zlabel=$z$, every axis x label/.style={ at={(ticklabel* cs:1.05)}, anchor=west, }, every axis y label/.style={ at={(ticklabel* cs:1.05)}, anchor=west, }, every axis z label/.style={ at={(ticklabel* cs:1.05)}, anchor=south, } ] \addplot3[ % mesh, surf, opacity=0.5, shader=faceted, samples=20, domain=0:2,y domain=0:2*pi, z buffer=sort] (x,{(60/(x+2))* cos(deg(y))},{(60/(x+2)) * sin(deg(y))}); % \draw[red, domain=0:pi/4, samples=200]plot(axis cs:0,{10* cos(deg(\x))}, {10* sin(deg(\x))}); \node at(axis cs:0,5,8) [anchor=west]{$\theta$}; % \draw[-stealth, red, domain=0:11*pi/4, samples=200]plot(axis cs:2.3,{6*cos(deg(\x))},{6*sin(deg(\x))}); % \draw[-stealth,red,thin] (axis cs:0,0,0) -- (axis cs:0,{30*cos(deg(pi/4))},{30*sin(deg(pi/4))}); \draw[dashed,thin] (axis cs:0,{30*cos(deg(pi/4))},0) -- (axis cs:0,{30*cos(deg(pi/4))},{30*sin(deg(pi/4))}); \draw[dashed,thin] (axis cs:0,0,{30*sin(deg(pi/4))}) -- (axis cs:0,{30*cos(deg(pi/4))},{30*sin(deg(pi/4))}); % \filldraw[orange, opacity=0.5, domain=0:2, samples=200]plot(axis cs:\x,{(60/(\x+2))},0) -- (axis cs:2,15,0) -- (axis cs:2,0,0)-- (axis cs:0,0,0) --(axis cs:0,30,0); \end{axis} \end{tikzpicture} \end{center}
その3
作成した図:

\begin{center} \begin{tikzpicture}[scale=2] \begin{axis}[ % title={Rotation of $f(x)$}, colormap/greenyellow, hide axis, view={0}{30},%15,30 axis lines=center, ticks=none, xmin=-2.5, xmax=3, ymin=-2.5, ymax=2.5, zmin=0, zmax=2 ] % \addplot3[ surf, opacity=0.5, shader=faceted, samples=30, domain=0:1,y domain=0:2*pi %,z buffer=sort ] ({cos(deg(y))},{sin(deg(y))},{x}); % \addplot3[ % mesh, surf, opacity=0.5, shader=faceted, samples=30, domain=1:2,y domain=0:2*pi %,z buffer=sort ] ({x*cos(deg(y))},{x*sin(deg(y))},{3/(x^3+2)}); % \addplot3[ surf, opacity=0.5, shader=faceted, samples=30, domain=0:3/10,y domain=0:2*pi %,z buffer=sort ] ({2*cos(deg(y))},{2*sin(deg(y))},{x}); % \filldraw[green, opacity=0.5, domain=1:2, samples=200]plot(axis cs:\x,0,{(3/(\x^3+2))}) -- (axis cs:2,0,3/10) -- (axis cs:2,0,0)-- (axis cs:1,0,0) --(axis cs:1,0,1); \draw[thin,domain=1:2, samples=200]plot(axis cs:\x,0,{(3/(\x^3+2))}) -- (axis cs:2,0,3/10) -- (axis cs:2,0,0)-- (axis cs:1,0,0) --(axis cs:1,0,1); % \draw[-stealth](axis cs:0,0,0) -- (axis cs:2.5,0,0)node[anchor=west]{$x$}; \draw[-stealth](axis cs:0,0,0) -- (axis cs:0,0,1.6)node[anchor=south]{$y$}; \draw[-stealth, red, domain=-pi/4:7*pi/4, samples=200]plot(axis cs:{0.2*cos(deg(\x))}, {0.2*sin(deg(\x))},1.4); \node at(axis cs:1,0,0)[anchor=south west]{$a$}; \node at(axis cs:2,0,0)[anchor=south west]{$b$}; \node at(axis cs:1,0,1)[anchor=west]{$\;y=f(x)$}; \end{axis} \end{tikzpicture} \end{center}
\begin{center} \begin{tikzpicture}[scale=2] \begin{axis}[ % title={Rotation of $f(x)$}, colormap/greenyellow, hide axis, view={0}{30},%15,30 axis lines=center, ticks=none, xmin=-2.5, xmax=3, ymin=-2.5, ymax=2.5, zmin=0, zmax=2 ] % 点線(奥:0~pi) \draw[thin, dashed, domain=0:pi, samples=200]plot(axis cs:{cos(deg(\x))}, {sin(deg(\x))},0); \draw[thin, dashed, domain=0:pi, samples=200]plot(axis cs:{cos(deg(\x))}, {sin(deg(\x))},1); \draw[thin, dashed, domain=0:pi, samples=200]plot(axis cs:{2*cos(deg(\x))}, {2*sin(deg(\x))},0); \draw[thin, dashed, domain=0:pi, samples=200]plot(axis cs:{2*cos(deg(\x))}, {2*sin(deg(\x))},3/10); % \addplot3[ surf, opacity=0.5, shader=faceted, samples=30, domain=0:24/43,y domain=0:2*pi %,z buffer=sort ] ({1.5*cos(deg(y))},{1.5*sin(deg(y))},{x}); % \addplot3[ % mesh, surf, opacity=0.5, shader=faceted, samples=30, domain=1.5:1.6,y domain=0:2*pi %,z buffer=sort ] ({x*cos(deg(y))},{x*sin(deg(y))},{3/(x^3+2)}); % \addplot3[ surf, opacity=0.5, shader=faceted, samples=30, domain=0:125/254,y domain=0:2*pi %,z buffer=sort ] ({1.6*cos(deg(y))},{1.6*sin(deg(y))},{x}); % \filldraw[green, opacity=0.3, domain=1:2, samples=200]plot(axis cs:\x,0,{(3/(\x^3+2))}) -- (axis cs:2,0,3/10) -- (axis cs:2,0,0)-- (axis cs:1,0,0) --(axis cs:1,0,1); \draw[thin, domain=1.5:1.6, samples=200]plot(axis cs:\x,0,{(3/(\x^3+2))}) -- (axis cs:1.6,0,125/254) -- (axis cs:1.6,0,0) -- (axis cs:1.5,0,0)-- (axis cs:1.5,0,24/43); % 点線(手前:pi~2pi) \draw[thin, dashed, opacity=0.5, domain=pi:2*pi, samples=200]plot(axis cs:{cos(deg(\x))}, {sin(deg(\x))},0); \draw[thin, dashed, domain=pi:2*pi, samples=200]plot(axis cs:{cos(deg(\x))}, {sin(deg(\x))},1); \draw[thin, dashed](axis cs:1,0,1) -- (axis cs:1,0,0); \draw[thin, dashed](axis cs:-1,0,1) -- (axis cs:-1,0,0); \draw[thin, dashed, domain=pi:2*pi, samples=200]plot(axis cs:{2*cos(deg(\x))}, {2*sin(deg(\x))},0); \draw[thin, dashed, domain=pi:2*pi, samples=200]plot(axis cs:{2*cos(deg(\x))}, {2*sin(deg(\x))},3/10); \draw[thin, dashed, domain=1:2, samples=200]plot(axis cs:\x,0,{(3/(\x^3+2))}) -- (axis cs:2,0,0); \draw[thin, dashed, domain=1:2, samples=200]plot(axis cs:{-\x},0,{(3/(\x^3+2))}) -- (axis cs:-2,0,0); % 断面 \draw[-stealth](axis cs:0,0,0) -- (axis cs:2.5,0,0)node[anchor=west]{$x$}; \draw[-stealth](axis cs:0,0,0) -- (axis cs:0,0,1.6)node[anchor=south]{$y$}; \draw[-stealth, red, domain=-pi/4:7*pi/4, samples=200]plot(axis cs:{0.2*cos(deg(\x))}, {0.2*sin(deg(\x))},1.4); % \node at(axis cs:1.5,0,0)[anchor=south east]{$x$}; \node at(axis cs:1.55,0,0)[anchor=north]{$\mathrm{d}x$}; \draw[dashed](axis cs:0,0,24/43)node[anchor=east]{$f(x)$} -- (axis cs:1.5,0,24/43); \end{axis} \end{tikzpicture} \end{center}
応力テンソルの図
作成した図:
この図は,以下の記事で使っています:
\begin{center} \begin{tikzpicture}[scale=2.5] \begin{axis}[ title={Stress Tensor}, view={60}{30}, axis lines=center, ticks=none, xmin=0, xmax=50, ymin=0, ymax=50, zmin=0, zmax=50, xlabel=$x$, ylabel=$y$, zlabel=$z$, every axis x label/.style={ at={(ticklabel* cs:1.05)}, anchor=west, }, every axis y label/.style={ at={(ticklabel* cs:1.05)}, anchor=west, }, every axis z label/.style={ at={(ticklabel* cs:1.05)}, anchor=south, } ] % \node at(axis cs:20,20,20) [anchor=west]{$\boldsymbol{n}$}; \draw[-stealth,red,very thick] (axis cs:10,10,10) -- (axis cs:20,20,20); \draw[thin] (axis cs:30,0,0) -- (axis cs:0,30,0); \draw[thin] (axis cs:30,0,0) -- (axis cs:0,0,30); \draw[thin] (axis cs:0,30,0) -- (axis cs:0,0,30); \fill[orange, opacity=.2] (axis cs:30,0,0) -- (axis cs:0,30,0) -- (axis cs:0,0,30); \end{axis} \end{tikzpicture} \end{center}
ローレンツ変換
作成した図:
この図は,以下の記事で使っています:
\begin{center} \begin{tikzpicture}[scale=2] \draw [white](0,-1.5)--(0,1.5); %\node [anchor=north west] at (0,1.5) {$t>0$}; \draw [very thick, -stealth](0,{-3/8})--(0.6,{-3/8}) node [anchor=north]{$\bm{V}$}; % K \draw [very thick, -stealth]({-1/8},{-1/8})--(1/2,1/2) node [anchor=east]{$y\,$}; \draw [very thick, -stealth](-1/4,0)--(1,0) node [anchor=north]{$x$}; \draw [very thick, -stealth](0,-1/4)--(0,1) node [anchor=east]{$z$}; \node [anchor=north west] at (0,0) {$O$}; % K' \draw [-stealth, gray]({-1/8+0.6},{-1/8})--({1/2+0.6},1/2) node [anchor=east]{$y^{\prime}$}; \draw [-stealth, gray]({-1/4+0.6},0)--({1+0.6},0) node [anchor=north]{$x^{\prime}$}; \draw [-stealth, gray](0.6,-1/4)--(0.6,1) node [anchor=east]{$z^{\prime}$}; \node [gray, anchor=north west] at (0.6,0) {$O^{\prime}$}; \end{tikzpicture} \end{center}