我发现以下参考这会创建一个有底部的垂直圆柱体。但是我需要一个有底部的水平圆柱体,但似乎找不到一个简单(且可行)的示例。我尝试使用 tikz-3dplot 中的旋转坐标系,但无济于事。这是我的测试代码:
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot} %requires 3dplot.sty to be in same directory, or in your LaTeX installation
\usetikzlibrary{shapes.geometric,calc}
\title{TikZ: cylinder with bottom - example}
\begin{document}
\tdplotsetmaincoords{0}{0}
\begin{tikzpicture}[tdplot_main_coords]
\node[cylinder,draw=black,thick,aspect=0.7,minimum height=4cm,minimum width=3cm,shape border rotate=0,cylinder uses custom fill, cylinder body fill=red!30,cylinder end fill=red!10] (A) {A};
\tdplotsetrotatedcoords{0}{90}{0}
\draw[dashed,tdplot_rotated_coords]
let \p1 = ($ (A.after bottom) - (A.before bottom) $),
\n1 = {0.5*veclen(\x1,\y1)-\pgflinewidth},
\p2 = ($ (A.bottom) - (A.after bottom)!.5!(A.before bottom) $),
\n2 = {veclen(\x2,\y2)-\pgflinewidth}
in
([xshift=-\pgflinewidth] A.before bottom) arc [start angle=0, end angle=180,
x radius=\n1, y radius=\n2];
\end{tikzpicture}
\end{document}
答案1
像这样?
您只需要更改arc
绘制的方式。您的代码中有start angle=0,end angle=180
,所以它是椭圆的上半部分,而您需要的是右半部分。
起点是圆柱体的底部,因此您需要start angle=270
,并且要获取椭圆的正确部分,请使用delta angle=180
而不是end angle=90
。您还需要交换x
和y
半径,因此arc
命令变为
arc [start angle=270, delta angle=180,
x radius=\n2, y radius=\n1];
这些tikz-3dplot
东西不需要。完整代码:
\documentclass[tikz,border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}
\begin{document}
\begin{tikzpicture}
\node[cylinder,draw=black,thick,aspect=0.7,minimum height=4cm,minimum width=3cm,shape border rotate=0,cylinder uses custom fill, cylinder body fill=red!30,cylinder end fill=red!10] (A) {A};
\draw[dashed]
let \p1 = ($ (A.after bottom) - (A.before bottom) $),
\n1 = {0.5*veclen(\x1,\y1)-\pgflinewidth},
\p2 = ($ (A.bottom) - (A.after bottom)!.5!(A.before bottom) $),
\n2 = {veclen(\x2,\y2)-\pgflinewidth}
in
([xshift=-\pgflinewidth] A.before bottom) arc [start angle=270, delta angle=180,
x radius=\n2, y radius=\n1];
\end{tikzpicture}
\end{document}