3

I want to plot an optical fiber as in the picture below:

Optical fiber

As you can see, the drawing is composed of three concentric cylinders of different radii. This question is about drawing just one of those, say the right, small radius one.

My code up until now is this:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{3d}
\begin{tikzpicture}
%Opaque frame so it is easier to get the 3d visualization.
\begin{scope}[opacity=0.3]
\draw(-0.25,1,1) -- (0.25,1,1);
\draw(-0.25,1,1) -- (-0.25,1,-1);
\draw(-0.25,1,1) -- (-0.25,-1,1);
\draw(0.25,1,1) -- (0.25,1,-1);
\draw(0.25,1,1) -- (0.25,-1,1);
\draw(0.25,1,-1) -- (-0.25,1,-1);
\draw(0.25,1,-1) -- (0.25,-1,-1);
\draw(-0.25,1,-1) -- (-0.25,-1,-1);
\draw(-0.25,-1,1) -- (0.25,-1,1);
\draw(0.25,-1,-1) -- (0.25,-1,1);
\draw(0.25,-1,-1) -- (-0.25,-1,-1);
\draw(-0.25,-1,-1) -- (-0.25,-1,1);
\end{scope}
% Draw the cylinder planes
\begin{scope}[canvas is zy plane at x=0.25]
\draw (0,0) circle (1);
\end{scope}
\begin{scope}[canvas is zy plane at x=-0.25]
\draw (0,0) circle (1);
\end{scope}
% Draw the edges, this is the tricky part.
\draw (-0.25,1,0) -- (0.25,1,0);
\end{tikzpicture}
\end{document}

output:

enter image description here

As you can see this last command that makes a straight line from the upper visible part from right to left is not actually where it should be. Any one have an idea on how to parametrically derive the "correct 3d" coordinates for this kind of lines?

Alternatively, I tried working with shapes.geometric and its cylinder primitive:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{3d}
\usetikzlibrary {shapes.geometric}
\begin{tikzpicture}
\begin{scope}[opacity=0.3]
\draw(-0.25,1,1) -- (0.25,1,1);
\draw(-0.25,1,1) -- (-0.25,1,-1);
\draw(-0.25,1,1) -- (-0.25,-1,1);
\draw(0.25,1,1) -- (0.25,1,-1);
\draw(0.25,1,1) -- (0.25,-1,1);
\draw(0.25,1,-1) -- (-0.25,1,-1);
\draw(0.25,1,-1) -- (0.25,-1,-1);
\draw(-0.25,1,-1) -- (-0.25,-1,-1);
\draw(-0.25,-1,1) -- (0.25,-1,1);
\draw(0.25,-1,-1) -- (0.25,-1,1);
\draw(0.25,-1,-1) -- (-0.25,-1,-1);
\draw(-0.25,-1,-1) -- (-0.25,-1,1);
\end{scope}

\node[cylinder,draw,minimum height=0.5cm,minimum width=1] (c) {}; \end{tikzpicture} \end{document}

output:

enter image description here

Well not bad, but I have two questions about its specification:

  • How to set its front and ens planes?
  • How to set its radius to be equal to 2 so to fill up this rectangular prism's height and width? How to specify its depth to be equal to 0.5, as the prism's depth?
tush
  • 1,115
  • @SebGlav I came across this one. I posted this question because this answer looked too long with too many \newcommands. I am afraid there is no detour, and I need to carefully read this solution and write it down in my drawing in a cleaner way. – tush May 03 '21 at 18:08
  • 1
    It's not 3d but perhaps this post could be helpful too: https://tex.stackexchange.com/questions/578970/drawing-cylinder-3d-inside-each-other. – Juan Castaño May 04 '21 at 07:03
  • @JuanCastaño Thanks a lot! I will use this answer for my presentation I am working on these days. Still, I would like to know - one need to make some mathematical and geometrical calculations, regarding the view point and such, when drawing 3d geometrical shapes? Or perhaps the tikz engine has some capability of accepting 3d graphics primitives such as sphere, cone, tube and cylinder? – tush May 04 '21 at 09:18
  • Unfortunately, it's usually necessary to make these calculations especially if we are working in 3d and with revolution solids. There are tikz packages that provide some help (tikz-3dplot, for example) but some calculations are inevitable. – Juan Castaño May 04 '21 at 09:29

1 Answers1

5

There is an easy way to solve this in 3d: using an isometric perspective. But in this case I have rotated the axes, trying to make the drawing look like the OP's. I also have added a \newcommand which draws the cylinders and a background layer for the correct visualization.

\documentclass[border=2mm]{standalone}
\usepackage    {tikz}
\usetikzlibrary{3d}

% isometric axes \pgfmathsetmacro\xx{1/sqrt(2)} \pgfmathsetmacro\xy{1/sqrt(6)} \pgfmathsetmacro\zy{sqrt(2/3)}

% layers \pgfdeclarelayer{background} \pgfsetlayers {background,main}

\newcommand{\cylinder}[5] % center (left base), radius, height, color, opacity {% \begin{scope}[shift={#1}] \begin{pgfonlayer}{background} \draw[#4] (135:#2) arc (135:315:#2); \end{pgfonlayer} \draw[#4,top color=#4!40,fill opacity=#5] (-45:#2) arc (-45:135:#2) --++ (0,0,#3) arc (135:-45:#2) -- cycle; \draw[#4,fill=#4!60,fill opacity=#5,canvas is xy plane at z=#3] (0,0) circle (#2); \end{scope} }

\begin{document} \begin{tikzpicture}[line cap=round,line join=round,% isometric axes: x={(-\xx cm,-\xy cm)},y={(\xx cm,-\xy cm)},z={(0 cm,\zy cm)},% rotate=-100] % but rotated 100 degrees clockwise % \cylinder{(0,0,0)} {0.75}{4} {gray}{1} \cylinder{(0,0,0)} {1.25}{4} {red} {0.8} \cylinder{(0,0,0)} {1.5} {4} {blue}{0.7} \cylinder{(0,0,4)} {0.75}{1.5} {gray}{1} \cylinder{(0,0,4)} {1.25}{1.5} {red} {0.8} \cylinder{(0,0,5.5)}{0.75}{1.25}{gray}{1} \end{tikzpicture} \end{document}

enter image description here

Juan Castaño
  • 28,426