我正在 TiKz 中绘制一个立方体。立方体的中心位于原点。也就是说,当我显示立方体移动时,坐标仍然为 (±1,±1,±1)。在 x=0 处对齐,并且全部位于第一个(所有正坐标)立方中。
以下是一个简化的示例:
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc,3d,decorations.markings, backgrounds, positioning,intersections,shapes}
%\usepackage{tikz-3dplot}
\begin{document}
\begin{figure}[ht]
\begin{center}
%\tdplotsetmaincoords{60}{145}
\begin{tikzpicture}[scale=2]
\coordinate (O) at (0,0,0);
\coordinate (A) at (1,-1,1);
\coordinate (B) at (-1,-1,1);
\coordinate (C) at (-1,1,1);
\coordinate (D) at (1,1,1);
\coordinate (E) at (1,1,-1);
\coordinate (F) at (-1,1,-1);
\coordinate (G) at (-1,-1,-1);
\coordinate (H) at (1,-1,-1);
\draw[fill=black] (A) circle (1pt) node[anchor=west] {$A$};
\draw[fill=black] (B) circle (1pt) node[anchor=east] {$B$};
\draw[fill=black] (C) circle (1pt) node[anchor=east] {$C$};
\draw[fill=black] (D) circle (1pt) node[anchor=west] {$D$};
\draw[fill=black] (E) circle (1pt) node[anchor=west] {$E$};
\draw[fill=black] (F) circle (1pt) node[anchor=east] {$F$};
\draw[fill=black] (G) circle (1pt) node[anchor=west] {$G$};
\draw[fill=black] (H) circle (1pt) node[anchor=east] {$H$};
\draw[fill=blue] (O) circle (1pt) node[anchor=east] {$0$};
\coordinate (X) at (3,0,0);
\coordinate (Y) at (0,3,0);
\coordinate (Z) at (0,0,3);
\draw[opacity=0.2] (A)--(B)--(C)--(D)--cycle;
\draw[opacity=0.2] (E)--(F)--(G)--(H)--cycle;
\draw[opacity=0.2] (A)--(H);
\draw[opacity=0.2] (B)--(G);
\draw[opacity=0.2] (D)--(E);
\draw[opacity=0.2] (C)--(F);
\draw[-latex] (O) -- (X) node[anchor=west] {\; \; $X$};
\draw[-latex] (O) -- (Y) node[anchor=south] {$Y$};
\draw[-latex] (O) -- (Z) node[anchor=south] {$Z$};
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
下图是:
谢谢。
答案1
这是视觉错觉。
您可以通过 更改视角z=(...)
。这是简化版并带有扩展轴的代码。
\documentclass[12pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=2,z={(-.5,-.28)}]
\draw[latex-] (2.1,0,0) coordinate (X) node[anchor=west] {$X$} -- ([scale=-1]X);
\draw[latex-] (0,2.1,0) coordinate (Y) node[anchor=south] {$Y$} -- ([scale=-1]Y);
\draw[latex-] (0,0,3.5) coordinate (Z) node[anchor=east] {$Z$} -- ([scale=-1]Z);
\draw[fill=blue] coordinate (O) circle (1pt) node[anchor=south east] {$O$};
\draw[opacity=0.2]
(1,-1,1) coordinate (A) --
(-1,-1,1) coordinate (B) --
(-1,1,1) coordinate (C) --
(1,1,1) coordinate (D) -- cycle
(1,1,-1) coordinate (E) --
(-1,1,-1) coordinate (F) --
(-1,-1,-1) coordinate (G) --
(1,-1,-1) coordinate (H) -- cycle
(A)--(H) (B)--(G) (D)--(E) (C)--(F);
\foreach \l/\a in {A/north west,B/north east,C/south east,D/south east,E/south west,F/south east,G/north west,H/north west}
\draw[fill=black] (\l) circle (1pt) node[anchor=\a] {$\l$};
\end{tikzpicture}
\end{document}