# Understanding beams in pst-optexp

I'm apparently missing something fundamental in how beams interact with interfaces. I have prepared three simple examples, with the hopes that someone can explain to me why certain things happen.

# Example 1

This much makes sense. I have an incoming beam at normal incidence on a mirror, and the drawbeam statement is specified in the form (node){component}(node). The beam reflects back, just like you would expect it to.

\documentclass[pstricks]{standalone}
\usepackage{pst-optexp}
\begin{document}
\begin{pspicture}(-1.5,-1.5)(1.5,1.5)
\pnode(-1,0){in}
\pnode(0,0){mir}
\pnode(1,0){out}
\pnode(-1,-1){low}
\pnode(-1,1){high}
\mirror(low)(mir)(high)
\drawbeam[linecolor=red,arrows=->](in){1}(in)
% \drawbeam[linecolor=blue,arrows=->](low){1}(high)
\end{pspicture}
\end{document}


If I replace the drawbeam statement with (in){1}(out) the beam stops at the mirror (doesn't reflect and doesn't pass through). This makes sense, a beam shouldn't pass through a mirror that isn't transmissive (ideally, of course).

# Example 2

This case is pretty similar to the last one, the only difference is that the incoming beam is at an angle. Again, if the drawbeam statement is (low)(mir)(high) the beam stops at the mirror, but reflects if the statement is (low){1}(high).

\documentclass[pstricks]{standalone}
\usepackage{pst-optexp}
\begin{document}
\begin{pspicture}(-1.5,-1.5)(1.5,1.5)
\pnode(-1,0){in}
\pnode(0,0){mir}
\pnode(1,0){out}
\pnode(-1,-1){low}
\pnode(-1,1){high}
\mirror(low)(mir)(high)
% \drawbeam[linecolor=red,arrows=->](in){1}(in)
\drawbeam[linecolor=blue,arrows=->](low){1}(high)
\end{pspicture}
\end{document}


# Example 3

Here's something that just baffles me. Individually, the beams in examples 1 and 2 draw just fine when specified as (node){component}(node). When I draw them together, however, only the red arrow shows up (the picture is identical to the first picture in example 1). Why can't I have both beams drawn as specified below?

\documentclass[pstricks]{standalone}
\usepackage{pst-optexp}
\begin{document}
\begin{pspicture}(-1.5,-1.5)(1.5,1.5)
\pnode(-1,0){in}
\pnode(0,0){mir}
\pnode(1,0){out}
\pnode(-1,-1){low}
\pnode(-1,1){high}
\mirror(low)(mir)(high)
\drawbeam[linecolor=red,arrows=->](in){1}(in)
\drawbeam[linecolor=blue,arrows=->](low){1}(high)
\end{pspicture}
\end{document}


# Questions

• Why can't I specify the beam path as (node)(node)(node) rather than (node){component}(node)?
• Why can't I draw both of the beams in example 3?

# My Setup

• OS X Yosemite
• Edited in MacVim using latex-suite
• Compiled using xelatex -interaction=nonstopmode
• You can draw with three nodes, but then you could simply use \psline. The advantage of \drawbeam is, that it knows which interface to use, if a component has more than one, and also if it is transmittive or reflective, or curved etc. The third example is a bug. Can investigate this only in a few days. – Christoph Dec 26 '14 at 12:38

What you observed with your two questions can both be classified as bugs:

1. Running your third example which xelatex gives a ghostscript error, which is why you don't see the second beam. Using latex + dvips + ps2pdf works fine.

I don't use xelatex, and I don't know all the internal details about how it deals with Postscript code. There is one special hack in \drawbeam, which could be the culprit here. Don't know if I'll be able to fix it.

2. In general it should be possible to use three different nodes like with

\drawbeam(low)(mir)(high)


This should draw two lines, but actually draws only a single one from (low) to (mir). So, this is also a bug. However, to connect only nodes you don't need \drawbeam, but can likewise use \psline.

In general, the purpose of having components and connect them with \drawbeam is to have the reflection and refraction calculated automatically. By giving only a component name/number to the macro it can for itself select which interface to use, what its properties are, and draw the beam accordingly.

Consider using a semi-transparent mirror instead of a simple one:

\documentclass[pstricks]{standalone}
\usepackage{pst-optexp}
\begin{document}
\begin{pspicture}(-1.5,-1.5)(1.5,1.5)
\pnode(-1,0){in}
\pnode(0,0){mir}
\pnode(1,0){out}
\pnode(-1,-1){low}
\pnode(-1,1){high}
\mirror[mirrortype=semitrans, mirrordepth=-0.2](low)(mir)(high)
\drawbeam[linecolor=blue,arrows=->](low){1}(high)
\psdots(low)(mir)(high)
\end{pspicture}
\end{document}


You see, that the first node, (low) gives the starting point, and the center node of the mirror gives the direction of the starting beam. The rest is given by the laws of refraction and reflection. You'll also notice, that the beam doesn't end at the (high) node, because that doesn't fit to the traced beam path.