pgfplots
我可以通过以下代码制作球体。
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
axis equal,
width=10cm,
height=10cm,
axis lines = none,
% xlabel = {$x$},
% ylabel = {$y$},
% zlabel = {$z$},
ticks=none,
enlargelimits=0.3,
view/h=45,
scale uniformly strategy=units only,
]
\addplot3[%
opacity = 0.5,
surf,
z buffer = sort,
samples = 21,
variable = \u,
variable y = \v,
domain = 0:180,
y domain = 0:360,
]
({cos(u)*sin(v)}, {sin(u)*sin(v)}, {cos(v)});
\end{axis}
\end{tikzpicture}
\end{document}
我想知道如何用 获得这种旋转倾斜的球体pgfplots
。谢谢
答案1
1. 备注
有关解释和实施请参阅第 3 节的“附件”文件。
所有矩阵乘法运算都是使用 Mathematica 完成的。
要了解有关轮换的更多信息,请参阅https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations或者在当地大学选修经典力学课程,尤其是刚体动力学。
2. 实施
使用 或 进行编译pdflatex
。lualatex
已xelatex
在 TeXLive 2013 上测试。
\documentclass[DIV=16]{scrartcl}
\pagestyle{empty}
\usepackage{amsmath}
\usepackage{url}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
To rotate a body around a given axis, its parametrization vector $\boldsymbol{r}$
needs to be multiplied with the corresponding rotation matrix.
The parametrization vector of an ellipsoid is
%
\begin{equation*}
\boldsymbol{r}
=
\begin{pmatrix}
x \\
y \\
z \\
\end{pmatrix}
=
\begin{pmatrix}
a \sin\vartheta \cos\varphi \\
b \sin\vartheta \sin\varphi \\
c \cos\vartheta \\
\end{pmatrix}
\end{equation*}
%
with the half-axes $a,b,c$.
\textbf{Example:} Rotation around the $z$-axis at the angle $\alpha$.
%
\begin{align*}
\boldsymbol{r}^*
=
\mathcal{R}_z(\alpha) \cdot \boldsymbol{r}
&=
\begin{pmatrix}
\cos\alpha & -\sin\alpha & 0 \\
\sin\alpha & \cos\alpha & 0 \\
0 & 0 & 1 \\
\end{pmatrix}
\cdot
\begin{pmatrix}
a \sin\vartheta \cos\varphi \\
b \sin\vartheta \sin\varphi \\
c \cos\vartheta \\
\end{pmatrix}
\\
&=
\begin{pmatrix}
a \cos\alpha \sin\vartheta \cos\varphi - b \sin\alpha \sin\vartheta \sin\varphi \\
b \cos\alpha \sin\vartheta \sin\varphi + a \sin\alpha \sin\vartheta \cos\varphi \\
c \cos\vartheta \\
\end{pmatrix}
\end{align*}
\begin{center}
\def\a{2}
\def\b{1}
\def\c{0.5}
\def\z{30}
\begin{tikzpicture}
\begin{axis}[%
axis equal,
width=20cm,
height=20cm,
axis lines = center,
ticks=none,
view/h=45,
enlargelimits=0.3,
scale uniformly strategy=units only,
]
\addplot3[%
opacity = 0.5,
surf,
z buffer = sort,
samples = 21,
variable = \u,
variable y = \v,
domain = 0:180,
y domain = 0:360,
]
(
{\a*cos(\z)*sin(u)*cos(v) + \b*sin(\z)*sin(u)*sin(v)},
{\b*cos(\z)*sin(u)*sin(v) - \a*sin(\z)*sin(u)*cos(v)},
{\c*cos(u)}
);
,
,
\end{axis}
\end{tikzpicture}
\end{center}
\textbf{Example:} Rotation around the $z$-axis at the angle $\alpha$ and the $x$-axis at the angle $\beta$. This is analogous to the example above except, that now we need to multiply the vector with two rotation matrices. Keep in mind, that rotations do not commute! That means if you rotate around the $z$-axis first and then around the $x$-axis you are really rotating around the $x^*$-axis, which was created when rotating around the $z$-axis.
%
\begin{align*}
\boldsymbol{r}^*
&=
\mathcal{R}_x(\beta) \cdot \mathcal{R}_z(\alpha) \cdot \boldsymbol{r}
\\
&=
\begin{pmatrix}
1 & 0 & 0 \\
0 & \cos\beta & -\sin\beta\\
0 & \sin\beta & \cos\beta \\
\end{pmatrix}
\cdot
\begin{pmatrix}
\cos\alpha & -\sin\alpha & 0 \\
\sin\alpha & \cos\alpha & 0 \\
0 & 0 & 1 \\
\end{pmatrix}
\cdot
\begin{pmatrix}
a \sin\vartheta \cos\varphi \\
b \sin\vartheta \sin\varphi \\
c \cos\vartheta \\
\end{pmatrix}
\\
&=
\begin{pmatrix}
a \cos\alpha \cos\varphi \sin\vartheta
- b \sin\alpha \sin\vartheta \sin\varphi
\\
- c \cos\vartheta \sin\beta
+ a \cos\beta \cos\varphi \sin\alpha \sin\vartheta
+ b \cos\alpha \cos\beta \sin\vartheta \sin\varphi
\\
c \cos\beta \cos\vartheta
+ a \cos\varphi \sin\alpha \sin\beta \sin\vartheta
+ b \cos\alpha \sin\beta \sin\vartheta \sin\varphi \\
\end{pmatrix}
\end{align*}
\begin{center}
\def\a{2}
\def\b{1}
\def\c{0.5}
\def\z{30}
\def\x{15}
\begin{tikzpicture}
\begin{axis}[%
axis equal,
width=20cm,
height=20cm,
axis lines = center,
ticks=none,
view/h=45,
enlargelimits=0.3,
scale uniformly strategy=units only,
]
\addplot3[%
opacity = 0.5,
surf,
z buffer = sort,
samples = 21,
variable = \u,
variable y = \v,
domain = 0:180,
y domain = 0:360,
]
(
{\a*cos(v)*cos(\z)*sin(u) - \b*sin(u)*sin(v)*sin(\z)},
{\b*cos(\x)*cos(\z)*sin(u)*sin(v) - \c*cos(u)*sin(\x) + \a*cos(v)*cos(\x)*sin(u)*sin(\z)},
{\c*cos(u)*cos(\x) + \b*cos(\z)*sin(u)*sin(v)*sin(\x) + \a*cos(v)*sin(u)*sin(\x)*sin(\z)}
);
\end{axis}
\end{tikzpicture}
\end{center}
For more information about rotation matrices see \url{https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations}.
\end{document}
3. 输出
在 writeLaTeX 上,根据以下人员的建议进行了一些修改敲击, 谢谢你:https://www.writelatex.com/283014krmwmg