9

By using the TikZ package, I want to draw this:

enter image description here

and

enter image description here

For the results below, I still need help from GeoGebra. (It's hard for me to draw arcs in slanted position and in shading.)

\documentclass[border=10pt]{standalone}
\usepackage[x11names,dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{intersections,calc}

\begin{document}

\begin{tikzpicture}[font=\scriptsize]
\coordinate (A) at (0,0);
\coordinate (B) at (30:5.4);
\coordinate (C) at ($(A)!3cm!-90:(B)$);
\coordinate (D) at ($(B)!3cm!90:(A)$);
\coordinate (E) at (-20:6);
\coordinate (F) at (149:.5);
\coordinate (G) at ($(E)!3cm!-90:(F)$);
\coordinate (H) at ($(F)!3cm!90:(E)$);
\coordinate (K) at ($(A)!.5!(C)$);
\coordinate (L) at ($(B)!.5!(D)$);
\coordinate (M) at ($(E)!.5!(G)$);
\coordinate (N) at ($(F)!.5!(H)$);
\path[name path=g1] (A)--(B);
\path[name path=g2] (C)--(D);
\path[name path=g3] (E)--(F);
\path[name path=g4] (G)--(H);
\path [name intersections={of = g3 and g1, by={P}}];
\path [name intersections={of = g3 and g2, by={Q}}];
\path [name intersections={of = g4 and g1, by={R}}];

\path[preaction={fill=Emerald,nearly transparent}] (A)--(C)--(D)--(B)--cycle;
\path[preaction={fill=Emerald,nearly transparent}] (E)--(F)--(H)--(G)--cycle;
%\draw[] (A)--(B) (C)--(D) (E)--(F) (G)--(H);
\draw[thick,rotate=-150] 
  let 
  \p1=($(A)-(K)$), 
  \n1={veclen(\x1,\y1)}
  in
  (K) circle (1cm and \n1);
\draw[thick,rotate=24.5] 
  let 
  \p1=($(B)-(L)$), 
  \n1={veclen(\x1,\y1)}
  in
  (D) arc (-79:96:1cm and \n1);
\draw[thick,rotate=160] 
  let 
  \p1=($(G)-(M)$),
  \n1={veclen(\x1,\y1)}
  in
  (M) circle (1cm and \n1);
\draw[thick,rotate=-15] 
  let 
  \p1=($(F)-(N)$), 
  \n1={veclen(\x1,\y1)}
  in
  (F) arc (260:82.5:1cm and \n1);
%\foreach \t in {A,B,C,D,E,F,G,H,P,Q,R}
%\draw[fill] (\t) node[below] {\t} circle (1.5pt);
\end{tikzpicture}

\end{document}

enter image description here

2 Answers 2

7

Here is a way to draw those intersections of cylinders with addplot3 in TikZ/PGFPlots.

enter image description here enter image description here

The code for the X-cylinders.

\documentclass[border=3mm]{standalone}

\usepackage{pgfplots}
    \pgfplotsset{compat=1.15}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[%
        axis equal,
        enlargelimits = true,
        samples = 45, samples y = 45,
        axis lines = none, ticks = none,
        cyl/.style = {%
                surf,
                black!30!,
                variable = \u,
                variable y = \v,
                z buffer = sort,
                faceted color=black!70!,
                },
        view/h = 125, view/v = 25
        ]
    \addplot3[%         (-) X-SEMIAXIS
        cyl,
        domain = -3:3,
        y domain = 0:360,
        ] ({min(u,-abs(cos(v)))}, {cos(v)}, {sin(v)});

    \addplot3[%         (+) Y-SEMIAXIS
        cyl,
        domain = 0:360,
        y domain = -3:3,
        ] ({cos(u)}, {max(v,abs(cos(u)))}, {sin(u)});

    \addplot3[%         (-) Y-SEMIAXIS
        cyl,
        domain = 0:360,
        y domain = -3:3,
        ] ({cos(u)}, {min(-abs(cos(u)),v)}, {sin(u)});

    \addplot3[%         (+) X-SEMIAXIS
        cyl,
        domain = -3:3,
        y domain = 0:360,
        ] ({max(u,abs(cos(v)))}, {cos(v)}, {sin(v)});

    \end{axis}
\end{tikzpicture}

\end{document}

Here is the code for the T-cylinders with dimension cotes.

\begin{tikzpicture}
  \begin{axis}[%
        axis equal,
        enlargelimits=true,
        samples = 40, samples y = 40,
        axis lines=none, ticks=none,
        cyl/.style = {%
                surf,
                black!30!,
                variable = \u,
                variable y = \v,
                z buffer = sort,
                faceted color=black!70!,
                },
        view/h=135, view/v=35
        ]%

    % COTES
    \tikzstyle{cote} = [%
        blue, fill=white, 
        font=\footnotesize, 
        inner sep=0pt]
    \tikzstyle{clines} = [%
        thin, blue!80!]

    \draw[clines] (3,-2,0) -- (3,0,0);
    \draw[clines] (-3,-2,0) -- (-3,0,0);
    \draw[|<->|, >=latex, thin, blue!80!] (-3,-2,0) -- (3,-2,0);
    \node[cote] at (0,-2,0) {$L_1$};

    % X CYLINDER
    \addplot3[%
        cyl,
        domain = -3:3,
        y domain = 0:360,
        ] ({u}, {cos(v)}, {sin(v)});

    % Y CYLINDER
    \addplot3[%
        cyl,
        domain = 0:360,
        y domain = -3:3,
        ] ({cos(u)}, {max(v,abs(cos(u)))}, {sin(u)});

    \draw[clines] (0,3,0) -- (4.5,3,0);
    \draw[clines] (3,-1,0) -- (4.5,-1,0);
    \draw[|<->|, >=latex, thin, blue!80!] (4.5,-1,0) -- (4.5,3,0);
    \node[cote] at (4.5,1,0) {$L_2$};

    \end{axis}
\end{tikzpicture}

Notes:

  • Every half of cylinder was drawn in a different plot for better visualization and easy handling. Thanks to @Marmot's answer on my question Truncated cylinder in PGFPlots, I could separate the portions of truncated cylinders as halfs along both sides of their respective axis. The order of their appeareance in the plot has a reason: is to avoid overlaping in visualization.
  • In order to abbreviate the codes and make them easy for changes eventually with comodity, I created one style with needed keys for all the cylinders, where special features could be set to enhance layout.
1
  • 1
    Thanks for your amazing answers! I will adapt yours but I still waiting answers in "pure" TikZ.
    – kalakay
    Dec 17, 2017 at 3:25
11

If you are also open to considering a solution based on asymptote, you may consider

 \documentclass{article}
 \usepackage[inline]{asymptote}
 \begin{document}
 \thispagestyle{empty}
 \begin{asy}
  import graph3;
  import solids;

  size(0,150);
  currentprojection=orthographic(1,1/2,1/2);

  // usage revolution r = cylinder(start,radius,length,ax);
  revolution r=cylinder(O,1,8,X);
  draw(surface(r),gray,render(merge=true));
  revolution r=cylinder((4,-4,0),1,8,Y);
  draw(surface(r),gray(0.8),render(merge=true));
 \end{asy}

 \begin{asy}
  import graph3;
  import solids;

  size(0,150);
  currentprojection=orthographic(1,1/2,1/2);

  // usage revolution r = cylinder(start,radius,length,ax);
  revolution r=cylinder(O,1,8,X);
  draw(surface(r),gray,render(merge=true));
  revolution r=cylinder((4,0,0),1,4,Y);
  draw(surface(r),gray(0.8),render(merge=true));
  draw((3.5,-1,1) -- (0,-1,1),  arrow=Arrow3(TeXHead2));
  draw((4.5,-1,1) -- (8,-1,1),  arrow=Arrow3(TeXHead2));
  label("$L_1$",(4,-1,1));
 \end{asy}
 \end{document}

enter image description here

To the best of my knowledge, tikz does not yet have a true 3D engine, meaning that one has to do things like 3D lighting more or less by hand, but I might be wrong. I was also not sure if you really want the mesh (since there is none in your MWE), but it is not too difficult to add it.

3
  • Incredible! But I still pursue TikZ package.
    – kalakay
    Dec 3, 2017 at 4:30
  • @marmot: Do you mind adding mesh on it?
    – Black Mild
    Mar 10, 2020 at 20:12
  • as a supplement of mamot's answer: to add mesh on the surfaces, we control parameters nu and nv in meshpen. The complete code (run in asymptote.ualberta.ca): import solids; size(5cm); currentprojection=orthographic(1,1/2,1/2,zoom=.9); revolution r=cylinder(O,1,8,X); revolution s=cylinder((4,-4,0),1,8,Y); draw(surface(r),lightyellow,nu=2,nv=20,gray); draw(surface(s),lightcyan,nu=2,nv=20,brown);
    – Black Mild
    Jan 5 at 8:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .