
這兩個用於 3D 繪圖的 tikz 庫有什麼區別嗎?
我找到了文檔tikz-3dplot
我找到了有關的CTAN,但 \usetikzlibrary{3d} 沒有任何內容。
可能與tikz 3d 庫的文檔
答案1
tikz-3dplot
s
(最後沒有)自動載入3d
庫(以及calc
)。因此它具有該庫的所有功能,3d
只是因為它加載了它。此外,它還具有允許安裝 3D 視圖的命令,例如\tdplotsetmaincoords
和\tdplotsetrotatedcoords
)的命令,並且意味著繪製真實的 3D 繪圖(因此得名)。在 Ti 中安裝 3d 視圖的其他方法kZ是使用perspective
庫(該鍵稱為3d view
)或pgfplots
(該鍵是view
和類似的鍵)。不幸的是,這些包/庫之間的視角約定有所不同。
該庫的主要目的3d
是切換到坐標平面(例如canvas is xy plane at z=<z>
),一旦您建立了正確的 3D 視圖,這當然是最有意義的。
Ti 支援 3d 座標kZ 不用多說。然而,預定義視圖不是正交的。您可以透過仔細選擇x
、y
和 來修正此問題z
,但使用上述工具會更方便。
這個例子旨在說明其中一些陳述。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{perspective}
\begin{document}
\begin{tikzpicture}[cube/.style={insert path={
(-1,-1,-1) edge ++(0,0,2) -- (1,-1,-1) edge ++(0,0,2)
-- (1,1,-1) edge ++(0,0,2) -- (-1,1,-1) edge ++(0,0,2) -- cycle
(-1,-1,1) -- (1,-1,1) -- (1,1,1) -- (-1,1,1) -- cycle
}}]
\def\LabelPlanes{
\node[canvas is xy plane at z=1,transform shape]{xy plane};
\node[canvas is xz plane at y=1,transform shape]{xz plane};
\node[canvas is yz plane at x=1,transform shape]{yz plane};}
\begin{scope}[local bounding box=A]
\draw[cube];
\LabelPlanes
\end{scope}
\path (A.south) node[below]{plain Ti\emph{k}Z};
%
\tdplotsetmaincoords{70}{110}% theta,phi
\begin{scope}[xshift=4cm,tdplot_main_coords,local bounding box=B]
\draw[cube];
\LabelPlanes
\end{scope}
\path (B.south) node[below]{\texttt{tikz-3dplot}};
%
\begin{scope}[xshift=8cm,3d view={110}{20},% phi,90-theta of tikz-3dplot
local bounding box=C]
\draw[cube];
\LabelPlanes
\end{scope}
\path (C.south) node[below]{\texttt{perspective}};
\end{tikzpicture}
\end{document}
最左邊的圖片不是立方體的正投影,而是顯示可以在Ti中使用3d座標k馬上Z。下一張圖片顯示了相同投影和透視下的立方體tikz-3dplot
,可以看到緯度角(通常稱為 theta)的約定有所不同。這個範例也說明了該函式庫的一個(也許是主要)應用3d
:在座標平面上投影某些內容。如圖所示,這適用於節點,但當然也適用於繪圖和外部圖形。
請注意,透視庫的主要目的不是安裝 3D 視圖。相反,正如其名稱所示,它允許安裝 3 點透視圖,但此討論超出了本答案的範圍。