我意识到关于 Tikz 中的圆柱体有几个问题,但我还没有弄清楚如何将它们添加到我的图像中。
我有类似的东西:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,3d,arrows,shapes}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{46+90} % rotate 60 degrees around x axis, then 105 degrees about z
\begin{tikzpicture}[>=stealth', % arrow tip
tdplot_main_coords, %
scale=0.5 % scale
]
% XYZ axis
\draw[thick,->] (0,0,0) -- (6,0,0) node[anchor=north east]{\textbf{x}};
\draw[thick,->] (0,0,0) -- (0,6,0) node[anchor=north]{\textbf{y}};
\draw[thick,->] (0,0,0) -- (0,0,6) node[anchor=south]{\textbf{z}};
\draw[dotted] (0,0,0) circle (15);
\draw plot [mark=*, mark size=3] coordinates{(15,0,0)} node[anchor=south east]{S};
% my lousy attempt
\node [cylinder,draw=black,thick,aspect=0.5,minimum height=1cm,minimum width=0.25cm,shape border
rotate=0,cylinder uses custom fill, cylinder body fill=red!30,cylinder end fill=red!5] at (15,0,0){S};
\end{tikzpicture}
\end{document}
那里有一个 3D 坐标系,以及一个带有特定坐标“S”的大圆圈,我想要一个朝向 (0,0,0) 的圆柱体。但是我似乎无法实现此方向。
如果解决这个问题的唯一方法是手动绘制圆柱体,那么我在连接“盖子”时会遇到问题。我可以在 XY 平面以外的其他方向上绘制 2 个实心圆(如 @john Kormylo 在评论中所示),但我不知道如何“连接”这些圆
答案1
据我所知,这并不容易实现。因为节点形状总是绘制在画布上,但你需要一个三维的,所以我们需要手工绘制圆柱体。这在tikz-3dplot
准备好的旋转参考系中很容易完成。我设置了这个框架,使圆柱体的面在这个平面上。然后很容易画出圆形面。唯一的问题是在正确的位置画出边线。为此,我们需要在这个平面上找到正确的角度,为此,我前段时间创建了一个宏这里,我在这里称之为\rotatedtangentangle
。
综合起来,结果如下:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,3d,arrows,shapes}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{46+90} % rotate 60 degrees around x axis, then 105 degrees about z
\begin{tikzpicture}[>=stealth', % arrow tip
tdplot_main_coords, %
scale=0.5 % scale
]
\newcommand{\rotatedtangentangle}[1]{%
% find directions of projection
\path[tdplot_rotated_coords] (1,0,0);
\pgfgetlastxy{\axisxx}{\axisxy}
\path[tdplot_rotated_coords] (0,1,0);
\pgfgetlastxy{\axisyx}{\axisyy}
\path[tdplot_rotated_coords] (0,0,1);
\pgfgetlastxy{\axiszx}{\axiszy}
% angle of tangent
\pgfmathsetmacro{\rtang}{atan(-\axiszy/\axiszx)+180}
\pgfmathsetmacro{\angkorr}{atan(\axisyy/\axisyx)/2}
\pgfmathsetmacro{#1}{\rtang+\angkorr}
}%
% XYZ axis
\draw[thick,->] (0,0,0) -- (6,0,0) node[anchor=north east]{\textbf{x}};
\draw[thick,->] (0,0,0) -- (0,6,0) node[anchor=north]{\textbf{y}};
\draw[thick,->] (0,0,0) -- (0,0,6) node[anchor=south]{\textbf{z}};
\draw[dotted] (0,0,0) circle (15);
\tdplotsetthetaplanecoords{90} % create rotated frame
\rotatedtangentangle{\tangent} % compute tanget angle
% shift rotated frame to center of cylinder
\coordinate (shift) at (15,0,0);
\tdplotsetrotatedcoordsorigin{(shift)}
% draw cylinder
\begin{scope}[tdplot_rotated_coords]
% draw the side lines and arc of the cylinder (here length 1, radius 0.5)
\draw[fill=red!30]
(0,0,-1) ++(\tangent:0.5) -- ++(0,0,1) arc (\tangent:\tangent-180:0.5) -- ++(0,0,-1);
% draw the circular face (radius 0.5)
\draw[fill=red!30] (0,0,-1) circle [radius=0.5];
\node at (0,0,0) {S};
\end{scope}
\end{tikzpicture}
\end{document}