我使用了tikz-3dplot
很多方法来绘制坐标系(通常在一个图形中使用多个坐标系),但我对“原点”的外观并不满意。例如,
\documentclass[tikz]{standalone}
\usepackage{tikz-3dplot}
\tikzset{
axis/.style={-stealth,line width=2pt,every node/.append style={text=black}},
xaxis/.style={axis,red},
yaxis/.style={axis,green},
zaxis/.style={axis,blue},
}
\begin{document}
\tdplotsetmaincoords{70}{115}
\begin{tikzpicture}[tdplot_main_coords]
\draw[xaxis] (0,0,0) -- (1,0,0) node[pos=1.3]{\( x \)};
\draw[yaxis] (0,0,0) -- (0,1,0) node[pos=1.3]{\( y \)};
\draw[zaxis] (0,0,0) -- (0,0,1) node[pos=1.3]{\( z \)};
\end{tikzpicture}
\end{document}
结果是
我的问题(显然)在于这一部分
现在我知道,我通常会提出我希望看到的结果,但问题是双重的,因为我也不确定我到底想看到什么。有没有人有解决方案可以显示更漂亮的结果?我应该补充一点,坐标系的方向不是固定的,所以解决方案在每个方向上都应该是漂亮的。
答案1
我从评论中收集了一些答案。
基本风格
\documentclass[tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows.meta}
\tikzset{
axis/.style={-stealth,line width=2pt,every node/.append style={text=black}},
xaxis/.style={axis,red},
yaxis/.style={axis,green},
zaxis/.style={axis,blue},
}
\begin{document}
\foreach \rotationangle in {115,120,...,470}{
\tdplotsetmaincoords{70}{\rotationangle}
\begin{tikzpicture}
\clip (-1.5,-0.75) rectangle (1.5,1.5);
\begin{scope}[tdplot_main_coords]
\draw[xaxis] (0,0,0) -- (1,0,0) node[pos=1.3]{\( x \)};
\draw[yaxis] (0,0,0) -- (0,1,0) node[pos=1.3]{\( y \)};
\draw[zaxis] (0,0,0) -- (0,0,1) node[pos=1.3]{\( z \)};
\end{scope}
\end{tikzpicture}
}
\end{document}
使用line cap=round
感谢@AlexG。
axis/.style={-stealth,line width=2pt,every node/.append style={text=black},line cap=round},
用球过度绘制
\filldraw[red] (0,0,0) circle [radius=0.04cm];
使用阴影球进行过度绘制
\shade [ball color=black] (0,0,0) circle [radius=0.04cm];
答案2
和 Max Snippe 的回答很相似,只是我回收了一些tikz-3dplot 的替代品,可以让你轻松地绕三个轴旋转(另见Max Snippe 的不错选择),更重要的\pgflowlevelsynccm
是,更加像 3D 的箭头。(原点处的阴影球改编自 AlexG/Max Snippe 联盟。;-)
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{3d}
\makeatletter
%from https://tex.stackexchange.com/a/375604/121799
%along x axis
\define@key{x sphericalkeys}{radius}{\def\myradius{#1}}
\define@key{x sphericalkeys}{theta}{\def\mytheta{#1}}
\define@key{x sphericalkeys}{phi}{\def\myphi{#1}}
\tikzdeclarecoordinatesystem{x spherical}{% %%%rotation around x
\setkeys{x sphericalkeys}{#1}%
\pgfpointxyz{\myradius*cos(\mytheta)}{\myradius*sin(\mytheta)*cos(\myphi)}{\myradius*sin(\mytheta)*sin(\myphi)}}
%along y axis
\define@key{y sphericalkeys}{radius}{\def\myradius{#1}}
\define@key{y sphericalkeys}{theta}{\def\mytheta{#1}}
\define@key{y sphericalkeys}{phi}{\def\myphi{#1}}
\tikzdeclarecoordinatesystem{y spherical}{% %%%rotation around x
\setkeys{y sphericalkeys}{#1}%
\pgfpointxyz{\myradius*sin(\mytheta)*cos(\myphi)}{\myradius*cos(\mytheta)}{\myradius*sin(\mytheta)*sin(\myphi)}}
%along z axis
\define@key{z sphericalkeys}{radius}{\def\myradius{#1}}
\define@key{z sphericalkeys}{theta}{\def\mytheta{#1}}
\define@key{z sphericalkeys}{phi}{\def\myphi{#1}}
\tikzdeclarecoordinatesystem{z spherical}{% %%%rotation around x
\setkeys{z sphericalkeys}{#1}%
\pgfpointxyz{\myradius*sin(\mytheta)*cos(\myphi)}{\myradius*sin(\mytheta)*sin(\myphi)}{\myradius*cos(\mytheta)}}
\makeatother
% definitions to make your life easier
\tikzset{rotate axes about y axis/.code={
\path (y spherical cs:radius=1,theta=90,phi=0+#1) coordinate(xpp)
(y spherical cs:radius=1,theta=00,phi=90+#1) coordinate(ypp)
(y spherical cs:radius=1,theta=90,phi=90+#1) coordinate(zpp);
},rotate axes about x axis/.code={
\path (x spherical cs:radius=1,theta=00,phi=90+#1) coordinate(xpp)
(x spherical cs:radius=1,theta=90,phi=00+#1) coordinate(ypp)
(x spherical cs:radius=1,theta=90,phi=90+#1) coordinate(zpp);
},
rotate axes about z axis/.code={
\path (z spherical cs:radius=1,theta=90,phi=#1) coordinate(xpp)
(z spherical cs:radius=1,theta=90,phi=90+#1) coordinate(ypp)
(z spherical cs:radius=1,theta=00,phi=#1) coordinate(zpp);
},
pitch/.style={rotate axes about y axis=#1,x={(xpp)},y={(ypp)},z={(zpp)}},
roll/.style={rotate axes about x axis=#1,x={(xpp)},y={(ypp)},z={(zpp)}},
yaw/.style={rotate axes about z axis=#1,x={(xpp)},y={(ypp)},z={(zpp)}}
}
\tikzset{
axis/.style={-stealth,line width=2pt,every node/.append style={text=black}},
xaxis/.style={axis,red},
yaxis/.style={axis,green},
zaxis/.style={axis,blue},
}
\begin{document}
\foreach\X in {0,5,...,355}
{\begin{tikzpicture}[yaw=00,scale=2]
\draw (-3,3,0) rectangle (3,-2,0);
\begin{scope}[pitch=\X]
\begin{scope}[canvas is xz plane at y=0,transform shape]
\pgflowlevelsynccm
\draw[yaxis] (0,0,0) -- (0,1);
\draw[xaxis] (0,0,0) -- (1,0);
\end{scope}
\draw[zaxis] (0,0,0) -- (0,1,0) node[pos=1.3]{\( z \)};
\node at (1.3,0,0) {\( x \)};
\node at (0,0,1.3) {\( y \)};
\end{scope}
\shade[ball color=black](0,0,0) circle (1mm);
\end{tikzpicture}}
\end{document}