6

I would like to draw a ruby laser like in images bellow laser1 or laser2 What I did so far is taken from How can I draw nucleosomes with wrapped DNA in tikz or pstricks?. The problem is that the glass tube around the ruby(see tikz code below), doesn't have a real look of glass tube! please any help? Any codes in tikz, asymptote or pstricks are welcomed! laser3

\documentclass[tikz, border=2mm]{standalone}
\usepackage{tikz}
\begin{document}

\pgfdeclarelayer{backwrapping}
\pgfdeclarelayer{frontwrapping}
\pgfsetlayers{backwrapping,main,frontwrapping}

\tikzset{
 wrapping/.style={
    draw=cyan!90, 
    line cap=round, 
    line join=round, 
    ultra thick},
 nucleosome/.style={
    fill=red!40, 
    fill opacity=.9, 
    draw=none},
top cylinder/.style={
    fill=red!60, 
    fill opacity=.9
 }
}


\begin{tikzpicture}[scale=0.75]
\foreach \q [remember=\q as \p] in {1}{
\begin{scope}[shift={(\q*3,0)}, rotate=0]
 \path [nucleosome] 
 (0,1) 
arc (90:270:0.375 and 1) -- (4.25,-1) 
arc (270:90:0.375 and 1) -- cycle;
\path [top cylinder] 
(4.625, 0) arc (0:360:0.375 and 1) -- cycle;

\begin{scope}[shift={(0.25,0)}]
\begin{pgfonlayer}{backwrapping}
\draw [wrapping] 
(0.25, -1.125) 
\foreach \i in {180,185,...,360}{ -- (\i/720+0.375*sin -\i, 1.125*cos \i)}[shift={(0.5,0)}]
(0.25, -1.125) 
\foreach \i in {180,185,...,360}{ -- (\i/720+0.375*sin -\i, 1.125*cos \i)}[shift={(0.5,0)}]
(0.25, -1.125) 
\foreach \i in {180,185,...,360}{ -- (\i/720+0.375*sin -\i, 1.125*cos \i)}[shift={(0.5,0)}]
(0.25, -1.125)
\foreach \i in {180,185,...,360}{ -- (\i/720+0.375*sin -\i, 1.125*cos \i)}[shift={(0.5,0)}]
(0.25, -1.125)
\foreach \i in {180,185,...,360}{ -- (\i/720+0.375*sin -\i, 1.125*cos \i)}[shift={(0.5,0)}]
(0.25, -1.125)
\foreach \i in {180,185,...,360}{ -- (\i/720+0.375*sin -\i, 1.125*cos \i)}[shift={(0.5,0)}]
(0.25, -1.125)
\foreach \i in {180,185,...,360}{ -- (\i/720+0.375*sin -\i, 1.125*cos \i)}[shift={(0.5,0)}]
(0.25, -1.125);
%\draw [wrapping] (0, 1.125)  arc(90:0:0.125cm and 0.25cm) arc(0:-90:1cm and 1cm) coordinate (wrapping-start-\q);
\end{pgfonlayer}

\begin{pgfonlayer}{frontwrapping}
\draw [wrapping] 
(0, 1.125)  
\foreach \i in {0,5,...,180}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,180}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,180}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,180}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,180}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125)
\foreach \i in {0,5,...,180}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,180}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125)
\foreach \i in {0,5,...,150}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)} coordinate (wrapping-end-\q);
\end{pgfonlayer}
\end{scope}
\ifnum\q>1
\draw [wrapping] (wrapping-end-\p) .. controls ++(-60:0.5cm)  and ++(180:0.25cm) .. (wrapping-start-\q);
\fi
\ifnum\q=2
\draw [wrapping] (wrapping-end-\q) arc (210:270:1cm and 0.75cm);
\fi
\end{scope}
}
\end{tikzpicture}
\end{document}
  • you'v tagged the question pst-coil but given a tikz example, which seems rather inconsistent. Is this really a duplicate of the earlier corkscrew question? – David Carlisle Jan 2 '16 at 15:00
  • 1
    In order to publish a question I need a tag, thus I have tried coil, helix, spring as well as screw but such tags do not exist, and taking into account that I don't have a privilege to add a new tag, for this reason I pick up the closest one. Concerning your second question, yes the questions are related but in order do not confuse things let the screw be screw and what is related to laser to be related to laser. – Andrei Jan 2 '16 at 16:55
  • you might at least add tikz-pdf if you want tikz answers, or say in words whether you need tikz or pstricks (incidentally why not just include the image) – David Carlisle Jan 2 '16 at 17:01
  • 2
    I think you are asking for something impossible. Rendering real-looking glass would need to be done by the kind of software which is designed to render realistic 3d, including lighting effects, reflections etc. That is simply not something which is practicable using TikZ or pstricks or similar. These kinds of solutions work well for diagrams, especially in 2D and to a limited extent in (faked-) 3D. But genuine-looking glass would require genuine 3D-rendering, as far as I know, because light and reflection is essential. Render and include the image with graphicx. – cfr Jan 3 '16 at 3:21
  • (Obviously in theory, you can do it with 2D because you could theoretically put each pixel in the appropriate spot or do some comparable vectorish thing. And, yes, TeX is Turing-complete. But none of that makes it actually doable in a practical sense.) – cfr Jan 3 '16 at 3:23
14

Here's an attempt using Asymptote. It's not perfect since transparent surfaces are a bit buggy, but I doubt any other TeX-related solution can come even this close.

cylinder with glass spiral around it

% file: foo.tex
% to compile: pdflatex --shell-escape foo
%
% For MikTeX users: Asymptote requires a separate program that cannot be installed
% by the package manager. You can get the installation file from
% https://sourceforge.net/projects/asymptote/files/2.35/
% (specifically, the file ending in setup.exe).
\documentclass{standalone}
\usepackage{asypictureB}
\begin{document}
\begin{asypicture}{name=RubyLaser}
settings.outformat = "png";
settings.render = 8;
size(10cm);
import graph3;

currentprojection = perspective(30, 50, 7);
currentlight = White;

triple f(real t) {
  return (t, cos(2pi*t), sin(2pi*t));
}

path3 helix = graph(f, 0, 8, n=500, operator..);

surface helixtube = tube(helix, width=0.4).s;

draw(helixtube, surfacepen=material(white+opacity(0.3), emissivepen=0.2*white));
draw(extrude(circle(O, r=0.6, normal=X), axis=8X), surfacepen=red+opacity(1.0));
\end{asypicture}
\end{document}
  • 1
    Perhaps, the ends of the central cylinder should be closed. Now it looks like a tube. – AlexG Jan 5 '16 at 9:21
4

Don’t have enough rep for commenting.

The easiest way of making something look like glass is to add one or two well placed highlights. I edited your code to add a single highlight. one or more additional highlights, shadows will give an impression of glass.

Also, as in Charle's answer, make the tube thicker so that there is enough pixels to apply any special effects on.

\documentclass[tikz, border=2mm]{standalone}
\usepackage{tikz}
\begin{document}

\pgfdeclarelayer{backwrapping}
\pgfdeclarelayer{frontwrapping}
\pgfsetlayers{backwrapping,main,frontwrapping}

\tikzset{
 wrapping/.style={
    draw=cyan!90, 
    line cap=round, 
    line join=round, 
    line width = 4pt},
 wrappinghighlight/.style={
    draw=white!90, 
    opacity = .9,
    line cap=round, 
    line join=round, 
    line width = 2pt},
 nucleosome/.style={
    fill=red!40, 
    fill opacity=.9, 
    draw=none},
top cylinder/.style={
    fill=red!60, 
    fill opacity=.9
 }
}


\begin{tikzpicture}[scale=0.75]
\foreach \q [remember=\q as \p] in {1}{
\begin{scope}[shift={(\q*3,0)}, rotate=0]
 \path [nucleosome] 
 (0,1) 
arc (90:270:0.375 and 1) -- (4.25,-1) 
arc (270:90:0.375 and 1) -- cycle;
\path [top cylinder] 
(4.625, 0) arc (0:360:0.375 and 1) -- cycle;

\begin{scope}[shift={(0.25,0)}]
\begin{pgfonlayer}{backwrapping}
\draw [wrapping] 
(0.25, -1.125) 
\foreach \i in {180,185,...,360}{ -- (\i/720+0.375*sin -\i, 1.125*cos \i)}[shift={(0.5,0)}]
(0.25, -1.125) 
\foreach \i in {180,185,...,360}{ -- (\i/720+0.375*sin -\i, 1.125*cos \i)}[shift={(0.5,0)}]
(0.25, -1.125) 
\foreach \i in {180,185,...,360}{ -- (\i/720+0.375*sin -\i, 1.125*cos \i)}[shift={(0.5,0)}]
(0.25, -1.125)
\foreach \i in {180,185,...,360}{ -- (\i/720+0.375*sin -\i, 1.125*cos \i)}[shift={(0.5,0)}]
(0.25, -1.125)
\foreach \i in {180,185,...,360}{ -- (\i/720+0.375*sin -\i, 1.125*cos \i)}[shift={(0.5,0)}]
(0.25, -1.125)
\foreach \i in {180,185,...,360}{ -- (\i/720+0.375*sin -\i, 1.125*cos \i)}[shift={(0.5,0)}]
(0.25, -1.125)
\foreach \i in {180,185,...,360}{ -- (\i/720+0.375*sin -\i, 1.125*cos \i)}[shift={(0.5,0)}]
(0.25, -1.125);
%\draw [wrapping] (0, 1.125)  arc(90:0:0.125cm and 0.25cm) arc(0:-90:1cm and 1cm) coordinate (wrapping-start-\q);
\end{pgfonlayer}

\begin{pgfonlayer}{frontwrapping}
\draw [wrapping] 
(0, 1.125)  
\foreach \i in {0,5,...,180}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,180}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,180}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,180}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,180}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125)
\foreach \i in {0,5,...,180}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,180}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125)
\foreach \i in {0,5,...,150}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)} coordinate (wrapping-end-\q);

\draw [wrappinghighlight] 
(0, 1.125)  
\foreach \i in {0,5,...,50}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.47,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,50}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,50}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,50}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,50}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125)
\foreach \i in {0,5,...,50}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125) 
\foreach \i in {0,5,...,50}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)}
[shift={(0.5,0)}]
(0, 1.125)
\foreach \i in {0,5,...,50}{ -- (\i/720+0.375*sin -\i,1.125*cos \i)} coordinate (wrapping-end-\q);

\end{pgfonlayer}
\end{scope}
\ifnum\q>1
\draw [wrapping] (wrapping-end-\p) .. controls ++(-60:0.5cm)  and ++(180:0.25cm) .. (wrapping-start-\q);
\fi
\ifnum\q=2
\draw [wrapping] (wrapping-end-\q) arc (210:270:1cm and 0.75cm);
\fi
\end{scope}
}
\end{tikzpicture}
\end{document}

coil with highlights

Searching for photoshop/gimp tutorials for Mac OS Aqua effect will turn up some tutorials that explain what all highlights/shadows are required for a glassy effect. (not posting links here)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.