如何创建自定义 TikZ 节点“有底部的圆柱体”,其中圆柱体底部的隐藏线使用虚线显示。
类似于下面的创作,除了节点中心应该在圆柱体的中间(好像它位于 3D 圆柱体的中心),而不是在侧面的中心 - 它看起来不平衡
https://www.writelatex.com/1149537sksqzs#/2737083/
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}
\begin{document}
\begin{tikzpicture}
\node[cylinder,draw=black,thick,aspect=0.7,
minimum height=1.7cm,minimum width=1.5cm,
shape border rotate=90,
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)},
\p2 = ($ (A.bottom) - (A.after bottom)!.5!(A.before bottom) $),
\n2 = {veclen(\x2,\y2)}
in
(A.before bottom) arc [start angle=0, end angle=180,
x radius=\n1, y radius=\n2];
\end{tikzpicture}
\end{document}
答案1
Tarass 猜对了,这是线宽的问题,但它既影响圆弧半径,又影响初始点(A.before bottom)
。以下是可能的解决方法:
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}
\title{TikZ: cylinder with bottom - example}
\begin{document}
\begin{tikzpicture}
\node[cylinder,draw=black,thick,aspect=0.7,minimum height=1.7cm,minimum width=1.5cm,shape border rotate=90,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=0, end angle=180,
x radius=\n1, y radius=\n2];
\end{tikzpicture}
\end{document}