2

I'm trying to create a bent/curved 3D pipe. I have only managed to place 2 cylinders at 90 degrees to each other. How can I join them with curved lines and remove the un-needed parts of the two cylinders?

\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}

enter image description here

Roland
  • 6,655

2 Answers2

2

Not sure if this is exactly what you're looking for, but you can \draw an arc with option double and place ellipses at each end. Note the double distance should account for the line thickness to get a smooth join. The ellipses are filled white to cover the ends of the doubled line.

enter image description here

\documentclass{article}
\usepackage{tikz}

\begin{document} \begin{tikzpicture} \draw[double distance={10mm-.4pt}] (45:2) arc (45:135:2); \drawfill=white, rotate around={45:(45:2)} ellipse(5mm and 3mm); \drawfill=white, rotate around={45:(135:2)} ellipse(3mm and 5mm); \end{tikzpicture} \end{document}

You can extend the straight segments if you wish. Use node for easy placement of the ellipses.

enter image description here

\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}

This can be turned into a macro \pipebend that takes 5 arguments (one optional):

\pipebend[<extra length>]{<pipe diameter>}{<start angle>}{<end angle>}{<bend radius>}

So the code

\pipebend[1cm]{1.5cm}{190}{60}{3cm}\hspace{-5cm}\pipebend[1cm]{2cm}{135}{45}{2cm}\hspace{1cm}\pipebend{1cm}{225}{315}{2cm}

Produces the following result:

enter image description here

\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}

Sandy G
  • 42,558
1

A suggestion in TIKZ only from above (sorry for the lack of artistry):

\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}

enter image description here

Roland
  • 6,655