我正在尝试创建弯曲的 3D 管道。我只能将 2 个圆柱体以 90 度角放置。如何用曲线将它们连接起来并移除两个圆柱体上不需要的部分?
\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[cylinder, draw, shape aspect=1,rotate=200,minimum height=1cm,
fill=white,fill opacity=1]{} ;
\node[cylinder, draw, shape aspect=1,rotate=330,minimum height=0.8cm,
fill=white]{} ;
\end{tikzpicture}
\end{document}
答案1
不确定这是否正是您想要的,但您可以\draw
使用arc
with 选项double
并在每端放置省略号。请注意,double distance
应考虑线条粗细以获得平滑的连接。省略号填充为白色以覆盖双线的末端。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[double distance={10mm-.4pt}] (45:2) arc (45:135:2);
\draw[fill=white, rotate around={45:(45:2)}](45:2) ellipse(5mm and 3mm);
\draw[fill=white, rotate around={45:(135:2)}](135:2) ellipse(3mm and 5mm);
\end{tikzpicture}
\end{document}
如果需要,您可以延长直线段。用于node
轻松放置椭圆。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[double distance={10mm-.4pt}] (0,0)node(a){}--++(1,1) arc (135:45:2)--++(1,-1)node(b){};
\draw[fill=white, rotate around={135:(a)}] (a) ellipse(5mm and 3mm);
\draw[fill=white, rotate around={135:(b)}] (b) ellipse(3mm and 5mm);
\end{tikzpicture}
\end{document}
这可以变成一个\pipebend
接受 5 个参数(一个可选)的宏:
\pipebend[<extra length>]{<pipe diameter>}{<start angle>}{<end angle>}{<bend radius>}
因此代码
\pipebend[1cm]{1.5cm}{190}{60}{3cm}\hspace{-5cm}\pipebend[1cm]{2cm}{135}{45}{2cm}\hspace{1cm}\pipebend{1cm}{225}{315}{2cm}
产生以下结果:
\documentclass{article}
\usepackage{tikz}
\newcommand{\pipebend}[5][0]{\tikz{
\draw[double distance={#2-.4pt}] (0,0)node(a){}--++({#3+(sign(#4-#5))*90}:#1) arc (#3:#4:#5)--++({#4+(sign(#4-#5))*90}:#1)node(b){};
\draw[fill=white, rotate around={#3:(a)}] (a) ellipse(.5*#2 and .3*#2);
\draw[fill=white, rotate around={#4:(b)}] (b) ellipse(.5*#2 and .3*#2);
}} %\pipebend[<extra length>]{<diameter>}{<start angle>}{<end angle>}{<bend radius>}
\begin{document}
\pipebend[1cm]{1cm}{190}{45}{3cm}\hspace{-5cm}\pipebend[1cm]{1cm}{135}{45}{2cm}\hspace{1cm}\pipebend{1cm}{225}{315}{2cm}
\end{document}
答案2
仅来自上方的 TIKZ 建议(抱歉缺乏艺术性):
\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main}
\begin{document}
\begin{tikzpicture}
%cylinder
\begin{pgfonlayer}{main}
\begin{scope}
\clip[rotate=45] (-0.5,-0.25) rectangle (0.5,-1.6);
%\draw[red,rotate=45] (-0.5,-0.25) rectangle (0.5,-1.6);
\node[cylinder,draw=black,fill=white,thick,aspect=0.9,minimum height=3cm,minimum width=1cm,rotate=-45] (A) {};
\end{scope}
\end{pgfonlayer}
\begin{pgfonlayer}{bg}
\node[cylinder,draw=black,thick,aspect=0.9,minimum height=3cm,minimum width=1cm,rotate=-135] (A) {};
\end{pgfonlayer}
\draw[smooth,rounded corners] (-0.178,-0.528) -- (0,0) --(0.528,0.178);
\end{tikzpicture}
\end{document}