我尝试使用带有等距投影或斜投影(法语中为 perpective cavalière)的 tikz 绘制一个球体。
对于斜投影,您必须在 x 轴上放置一个距离的缩放因子(scal < 1)。但如果我希望我的球体看起来像一个不扭曲的球体,我必须将缩放比例设为零。因此,我获得了 (yz) 平面中的投影。以下是我的 tikz 源代码,您可以轻松地在等距投影和斜投影之间切换:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{2mm}
\tikzstyle{cavaliere} = [x={(-0.866cm,-0.5cm)},y={(1cm,0cm)},z={(0cm,1cm)}]
\tikzstyle{isometrique} = [x={(-0.866cm,-0.5cm)},y={(0.866cm,-0.5cm)},z={(0cm,1cm)}]
\tikzstyle{mesh} = [color=gray, opacity=0.4]
\begin{document}
%
% norm selection :
%
% if(isometrique)
%
\begin{tikzpicture}[isometrique]
\def\scal{1.}
% else if(cavaliere)
%
%\begin{tikzpicture}[cavaliere]
% \def\scal{0.3}
%
\coordinate (O) at (0,0,0);
\draw[->] (O) -- ({\scal * 3},0,0) node[below] {x};
\draw[->] (O) -- (0,3,0) node[below] {y};
\draw[->] (O) -- (0,0,3) node[right] {z};
\def\r{2.}
% meridiens
% \rho joue le role de theta
\foreach \phi in {0,10,...,170} {
\draw[mesh] ({\scal * \r * cos(\phi)}, {\r * sin(\phi)}, 0)
\foreach \rho in {5,10,...,360} {
--({\scal * \r * cos(\phi) * cos(\rho)}, {\r * sin(\phi) * cos(\rho)}, {\r * sin(\rho)})
} -- cycle;
}
% parallels
\foreach \rho in {-60, -40, -19.57, 0, 19.57, 40, 60} {
\draw[mesh] ({\scal * \r * cos(\rho)}, 0, {\r * sin(\rho)})
\foreach \phi in {5,10,...,360} {
-- ({\scal * \r * cos(\rho) * cos(\phi)}, {\r * cos(\rho) * sin(\phi)}, {\r * sin(\rho)})
} -- cycle;
}
\end{tikzpicture}
\end{document}
你知道如何在斜投影中绘制正确的球体吗?我更喜欢那个,因为我放入球体中的视图比等距投影更好。
谢谢
编辑:轴 z 垂直
\begin{tikzpicture}[x={(-0.385cm,-0.385cm)},y={(1cm,0cm)},z={(0cm,1cm)},scale=4]
\coordinate (O) at (0,0,0);
\draw[->] (O) -- (2,0,0) node[below] {x};
\draw[->] (O) -- (0,2,0) node[below] {y};
\draw[->] (O) -- (0,0,2) node[right] {z};
\foreach \z in {-0.98,-0.96,...,0.98} {%
\begin{scope}[canvas is xy plane at z=\z]
\draw[gray] (0,0) circle ({sqrt(1-\z*\z)});
\end{scope}}
\begin{scope}[canvas is zy plane at x=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\begin{scope}[canvas is zx plane at y=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\begin{scope}[canvas is xy plane at z=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\end{tikzpicture}
因此我得到了
答案1
简单的代码,最好使用arc
和来确定可见部分。
我认为结果是这样的:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{3D}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[scale=4]
\foreach \z in {-0.98,-0.96,...,0.98} {%
\begin{scope}[canvas is xy plane at z=\z]
\draw[gray] (0,0) circle ({sqrt(1-\z*\z)});
\end{scope}}
\begin{scope}[canvas is zy plane at x=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\begin{scope}[canvas is zx plane at y=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\begin{scope}[canvas is xy plane at z=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\end{tikzpicture}
\end{document}
如何改变轴
如果面向观察者的平面是 yz ,后退轴是 x ,那么一个点的投影如下:
y'= y + 1/2 cos(a) x
z'= z + 1/2 sin(a) x
如果您想要 k=0.5 和 a=45°,则需要像这样更改系统:
x = { ({-0.5*cos(45)},{-0.5*sin(45)})},
y = { (1cm,0cm)},
z = { (0cm,1cm)}
所以 x =(-0.35355,-0.35355)
。我不知道为什么在 pgf 中 z =(-0.385,-0.385)
。
可以尝试 a=30 度或 a=60 度。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{3D}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[x = { ({-0.5*cos(45)},{-0.5*sin(45)})},
y = { (1cm,0cm)},
z = { (0cm,1cm)},
scale = 4]
\foreach \x in {-0.98,-0.96,...,0.98} {%
\begin{scope}[canvas is zy plane at x=\x]
\draw[gray] (0,0) circle ({sqrt(1-\x*\x)});
\end{scope}}
\begin{scope}[canvas is zy plane at x=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\begin{scope}[canvas is zx plane at y=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\begin{scope}[canvas is xy plane at z=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\end{tikzpicture}
\end{document}
答案2
这是我从 altermundus 中改编的代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{3d}
\begin{document}
\begin{tikzpicture}[x={({cos(135)},{-sin(45)})},y={(1cm,0cm)},z={(0cm,1cm)},scale=4]
\coordinate (O) at (0,0,0);
\draw[->] (O) -- (2,0,0) node[below] {x};
\draw[->] (O) -- (0,2,0) node[below] {y};
\draw[->] (O) -- (0,0,2) node[right] {z};
\foreach \z in {-0.98,-0.96,...,0.98} {%
\begin{scope}[canvas is xy plane at z=\z]
\draw[gray] (0,0) circle ({sqrt(1-\z*\z)});
\end{scope}}
\begin{scope}[canvas is zy plane at x=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\begin{scope}[canvas is zx plane at y=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\begin{scope}[canvas is xy plane at z=0]
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\end{scope}
\end{tikzpicture}
\end{document}
我尝试将 z 垂直放置在页面上的 y 上,将 x 垂直放置在页面上,但看起来不太好,如下所示:
这很奇怪,因为在 altermundus 图上,z 轴似乎与垂直方向成 45° 角。