From 74eab85d64cec0e1252bb24e518e38287955a722 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Tue, 2 Jul 2013 22:49:44 +0000
Subject: c2l pst-optexp (2jul13)

git-svn-id: svn://tug.org/texlive/trunk@31072 c570f23f-e606-0410-a88d-b1316a301751
---
 .../source/latex/pst-optexp/pst-optexp.dtx         | 406 ++++++++++++++-------
 1 file changed, 284 insertions(+), 122 deletions(-)

(limited to 'Master/texmf-dist/source/latex/pst-optexp/pst-optexp.dtx')

diff --git a/Master/texmf-dist/source/latex/pst-optexp/pst-optexp.dtx b/Master/texmf-dist/source/latex/pst-optexp/pst-optexp.dtx
index 0447a1d2d4d..88d273c276b 100644
--- a/Master/texmf-dist/source/latex/pst-optexp/pst-optexp.dtx
+++ b/Master/texmf-dist/source/latex/pst-optexp/pst-optexp.dtx
@@ -18,7 +18,7 @@
 %<stylefile>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
 %<stylefile>\ProvidesPackage{pst-optexp}
 %<*stylefile>
-    [2013/06/07 v4.2 Optical experimental setups with PSTricks]
+    [2013/07/02 v4.3a Optical experimental setups with PSTricks]
 %</stylefile>
 %
 %<*driver>
@@ -4093,29 +4093,46 @@
 % \iffalse
 %<*ignore>
 % \fi
-\begin{pspicture}(13,3)
+\begin{pspicture}(0,-0.5)(14,3.2)
   \footnotesize
-  \pnode(0,0){A}\pnode(3,1.8){B}\pnode(6,0){C}
-  \psdot(A)\uput[90](A){\prm{in}}
-  \psdot(B)\uput[90](B){\prm{center}}
-  \psdot(C)\uput[90](C){\prm{out}}
+  \pnode(0,1){A}\pnode(2,2){B}\pnode(4,1){C}
+  \psdot(A)\uput[90](A){A}
+  \psdot(B)\uput[90](B){B}
+  \psdot(C)\uput[90](C){C}
   \optprism[prismsize=2](A)(B)(C)
   \psline[style=Refline, linestyle=dashed](A)(B)(C)
-  \newpsstyle{IfcDot}{dotstyle=+, linecolor=red, dotscale=1.5}
-  \psdot[style=CenterNode](\oenodeCenter{})
-  \psdot[style=IfcDot](\oenodeIn{})
-  \psdot[style=IfcDot](\oenodeOut{})
-  \rput[b](\oenodeCenter{}|0,0){\opt{prismalign=auto}}
-  \pnode(7,0){A}\pnode(10,1.8){B}\pnode(13,0){C}
-  \psdot(A)\uput[90](A){\prm{in}}
-  \psdot(B)\uput[90](B){\prm{center}}
-  \psdot(C)\uput[90](C){\prm{out}}
+  \newpsstyle{IfcDot}{dotstyle=+, linecolor=red, linewidth=1.5\pslinewidth}
+  \psdot[style=IfcDot](\oenodeCenter{})\uput{0.1}[-90](\oenodeCenter{}){\prm{center}}
+  \psdot[style=IfcDot](\oenodeIn{})\uput{0.1}[150](\oenodeIn{}){\prm{in}}
+  \psdot[style=IfcDot](\oenodeOut{})\uput{0.1}[30](\oenodeOut{}){\prm{out}}
+  \rput[t](\oenodeCenter{}|0,0.2){%
+    \begin{tabular}{@{}c@{}}\opt{prismalign=auto}\\\opt{prismtype=transmittive}\end{tabular}}
+
+  \pnode(5,1){A}\pnode(7,2){B}\pnode(9,1){C}
+  \psdot(A)\uput[90](A){A}
+  \psdot(B)\uput[90](B){B}
+  \psdot(C)\uput[90](C){C}
   \optprism[prismsize=2, prismalign=center](A)(B)(C)
   \psline[style=Refline, linestyle=dashed](A)(B)(C)
-  \psdot[style=CenterNode](\oenodeCenter{})
-  \psdot[style=IfcDot](\oenodeIn{})
-  \psdot[style=IfcDot](\oenodeOut{})
-  \rput[b](\oenodeCenter{}|0,0){\opt{prismalign=center}}
+  \newpsstyle{IfcDot}{dotstyle=+, linecolor=red, linewidth=1.5\pslinewidth}
+  \psdot[style=IfcDot](\oenodeCenter{})\uput{0.1}[-90](\oenodeCenter{}){\prm{center}}
+  \psdot[style=IfcDot](\oenodeIn{})\uput{0.1}[150](\oenodeIn{}){\prm{in}}
+  \psdot[style=IfcDot](\oenodeOut{})\uput{0.1}[30](\oenodeOut{}){\prm{out}}
+  \rput[t](\oenodeCenter{}|0,0.2){%
+    \begin{tabular}{@{}c@{}}\opt{prismalign=center}\\\opt{prismtype=transmittive}\end{tabular}}
+
+  \pnode(10,2){A}\pnode(12,1){B}\pnode(14,2){C}
+  \psdot(A)\uput[90](A){A}
+  \psdot(B)\uput[-90](B){B}
+  \psdot(C)\uput[90](C){C}
+  \optprism[prismsize=2, prismtype=reflective](A)(B)(C)
+  \psline[style=Refline, linestyle=dashed](A)(B)(C)
+  \newpsstyle{IfcDot}{dotstyle=+, linecolor=red, linewidth=1.5\pslinewidth}
+  \psdot[style=IfcDot](\oenodeCenter{})\uput{0.1}[90](\oenodeCenter{}){\prm{center}}
+  \psdot[style=IfcDot](\oenodeIn{})\uput{0.1}[-160](\oenodeIn{}){\prm{in}}
+  \psdot[style=IfcDot](\oenodeOut{})\uput{0.1}[-20](\oenodeOut{}){\prm{out}}
+  \rput[t](\oenodeCenter{}|0,0.2){%
+    \begin{tabular}{@{}c@{}}\opt{prismalign=auto}\\\opt{prismtype=reflective}\end{tabular}}
 \end{pspicture}
 % \iffalse
 %</ignore>
@@ -4169,6 +4186,33 @@
 % \numitem[1.5]{raprismsize}
 % \ifGERMAN Die Länge der Eingangsfläche.\fi
 % \ifENGLISH The length of the input plane.\fi
+%
+% \choitem[auto]{raprismalign}{auto, center}
+% \ifGERMAN Schaltet die automatische Positionierung der Komponente
+% vertikal zur Eingangsfläche ein oder aus:
+% \fi
+% \ifENGLISH Switch between automatic and fixed alignment of the
+% component vertical to the entrance interface:
+% \fi
+%
+% \begin{pspicture}(0,-0.5)(13,2)
+%   \pnode(0,1.6){A}\pnode(0,0.4){B}
+%   \rightangleprism(A)(2,1)(B)\psdot(\oenodeCenter{})
+%   \drawbeam(A){}(B)
+%   \pnode(3,1.2){A}\pnode(3,0.8){B}
+%   \rightangleprism(A)(5,1)(B)\psdot(\oenodeCenter{})
+%   \drawbeam(A){}(B)
+%   \rput[t](3,0){\opt{raprismalign=auto}}
+%   \psset{raprismalign=center}
+%   \pnode(7,1.6){A}\pnode(7,0.4){B}
+%   \rightangleprism(A)(9,1)(B)\psdot(\oenodeCenter{})
+%   \drawbeam(A){}(B)
+%   \pnode(10,1.2){A}\pnode(10,0.8){B}
+%   \rightangleprism(A)(12,1)(B)\psdot(\oenodeCenter{})
+%   \drawbeam(A){}(B)
+%   \rput[t](10,0){\opt{raprismalign=center}}
+% \end{pspicture}
+%
 % \end{optionlist}
 % 
 % \ifGERMAN\section{Pentaprisma}\fi
@@ -10748,7 +10792,7 @@
 \beamsplitter(M4f3)(BS4f)(CCD){BS}
 \optbox[position=end, label=0, optboxwidth=1](BS4f)(CCD){CCD}
 \lens[abspos=0.7](BS4f)(BSFwd){L}\lens[abspos=0.7](BSBwd)(M4f1){L}
-\addtopsstyle{Beam}{linewidth=2\pslinewidth}
+\addtopsstyle{Beam}{linewidth=2\pslinewidth, linejoin=2}
 \drawbeam{1-6}{11-14}{13}{12}{15}{18}{16}{17}{25}{23}{24}
 \drawbeam[beaminsidefirst]{6}{7}{10}{17}{16}{18}{26}{19-24}
 \end{pspicture}
@@ -11134,17 +11178,17 @@
 \begingroup
 \captionsetup[lstlisting]{format=poecaption}
 \begin{LTXexample}[pos=t, caption={\ifGERMAN Angepasst von \fi\ifENGLISH Adapted from \fi\doiurl{10.1103/PhysRevLett.105.263904}}, label={ex:wgm-pdc}]]
-\begin{pspicture}(0.6,2.3)(6.8,7.8)
+\begin{pspicture}(0.6,2.8)(6.8,7.8)
 \pnode(1,6){Laser}\pnode(1,5){M}
 \pnode(3,4){PR}\pnode(5,5){PT}\pnode(6,7){D1}
 \newpsstyle{Glass}{fillcolor=blue, fillstyle=solid, opacity=0.15, linecolor=blue!30!white}
 \begin{optexp}
   \optbox[position=start, innerlabel, optboxwidth=1.8](Laser)(M){Nd:YAG}
-  \optprism[style=Glass, compname=P, prismtype=reflective, prismangle=90, label=1 135](M)(PR)(PT){\begin{tabular}{@{}c@{}}diamond\\ prism\end{tabular}}
+  \optprism[style=Glass, compname=P, n=1, prismtype=reflective, prismangle=60, labeloffset=1.2](M)(PR)(PT){\begin{tabular}{@{}c@{}}diamond\\ prism\end{tabular}}
   \mirror(Laser)(M)(\oenodeIfc{2}{P})%
-  \lens[abspos=1.33, style=Glass](\oenodeIfc{2}{P})(M)%
+  \lens[abspos=1.05, style=Glass](\oenodeIfc{2}{P})(M)%
   \optprism[compname=PDet, style=Glass](\oenodeIfc{2}{P})(PT)(D1)%
-  \lens[abspos=1.33, style=Glass](\oenodeIfc{2}{P})(\oenodeOut{PDet})%
+  \lens[abspos=1.05, style=Glass](\oenodeIfc{2}{P})(\oenodeOut{PDet})%
   \newpsstyle{Beam}{linestyle=none, fillstyle=solid}%
   \drawwidebeam[fillcolor=green, beamwidth=0.2, beaminsidelast, beampathcount=5]{1}{3}{4}{2}%
   \drawwidebeam[fillcolor=orange, beaminsidefirst, startinsidecount=1, loadbeam, beaminsidelast]{2}{6}%
@@ -11861,6 +11905,51 @@
 % Version beachten müssen, und was sie bei älteren Dokumenten gegebenenfalls
 % ändern müssen um mit der neuen Version korrekt zu funktionieren.  \fi
 %
+%
+% \subsection{Version 4.3a}\label{sec:bwd-comp-4.3a}
+%
+% \begin{optionlist}
+% \poeitem{prismtype}
+% \ifGERMAN Die Option \Lkeyword{prismtype} war immer noch
+% «zusammengeschustert» und die automatische Positionierung war recht
+% willkürlich. Dies sollte nun endlich korrigiert sein, unter
+% Option \Lkeyword{prismalign} ist ein entsprechendes Beispiel zu sehen.
+% \fi
+% \ifENGLISH The option \Lkeyword{prismtype} was still not correctly
+% implemented, die automatic alignment was somewhat arbitrary. This
+% should be finally fixed, an example is shown for option
+% \Lkeyword{prismalign}.
+% \fi
+%
+% \poeitem{\cs{optprism}}
+% \ifGERMAN Die Positionierung der Beschriftung war nicht konsistent mit
+% anderen Komponenten, der Bezugspunkt war nicht der Mittelpunkt und
+% auch nicht fest. Das ist jetzt behoben, könnte aber leichte
+% Korrekturen an bestehenden Skizzen erfordern.
+% \fi
+% \ifENGLISH The positioning of the label was not consistent with other
+% components, the reference point was not the center point and did also
+% depend on the component rotation. This is fixed now, but could mean
+% little corrections for existing images.
+% \fi
+% 
+% \end{optionlist} 
+%
+% \subsection{Version 4.3}\label{sec:bwd-comp-4.3}
+%
+% \begin{optionlist}
+% \poeitem{\cs{rightangleprism}}
+% \ifGERMAN Die Ausrichtung des \Lcs{rightangleprism} und die
+% Positionierung der Beschriftung war falsch. Das kommt aber nur zum
+% tragen, wenn Eingangs- und Ausgangsvektor sehr unterschiedliche Längen
+% haben.
+% \fi
+% \ifENGLISH The alignment of the \Lcs{rightangleprism} and the
+% positioning of the label was wrong. This became apparent only if the
+% input and output vectors had very different lenghts. 
+% \fi
+% \end{optionlist}
+% 
 % \subsection{Version 4.2}\label{sec:bwd-comp-4.2}
 %
 % \begin{optionlist}
@@ -12296,6 +12385,16 @@
 %
 % \begin{changelog}
 %\patchcmd{\release}{\setlength{\itemsep}{0pt}}{\setlength{\itemsep}{0pt}\setlength{\parsep}{0pt}}{}{}
+%   \begin{release}{4.3a}{2013-07-02}
+%   \item Fixed tripole alignment bugs introduced in version 4.3.
+%   \item Again fixed the alignment of reflective \cs{optprism}\see{prm:prismalign}
+%   \item Fixed improper alignment of \cs{optprism} label\see{sec:bwd-comp-4.3a}
+%   \end{release}
+%   \begin{release}{4.3}{2013-06-28}
+%   \item Added option \opt{raprismalign}\see{prm:raprismalign}
+%   \item Fixed alignment of \cs{rightangleprism} and rotation of its
+%     label.
+%   \end{release}
 %   \begin{release}{4.2}{2013-06-07}
 %   \item Added option \opt{startinsidecount}\see{prm:startinsidecount}
 %   \item Added option \opt{stopinsidecount}\see{prm:stopinsidecount}
@@ -12303,10 +12402,12 @@
 %   \item Added option \opt{beamnodealign}\see{prm:beamnodealign}
 %   \item Added \cs{oeBeamVecMedian}\see{cs:oeBeamVecMedian}
 %   \item Added \cs{oeBeamCenter}\see{cs:oeBeamCenter}
-%   \item Modified the orientation of a reflective \cs{optprism}\see{sec:bwd-comp-4.2}
+%   \item Modified the orientation of a reflective
+%     \cs{optprism}\see{sec:bwd-comp-4.2}
 %   \item Fixed bug of \cs{optprism} and \cs{rightangleprism} inside
 %     an \env{optexp} environment.
-%   \item Fixed bug of wrong \cs{rightangleprism} rotation in special cases.
+%   \item Fixed bug of wrong \cs{rightangleprism} rotation in special
+%     cases.
 %   \item Fixed buggy handling of multiple saved beams\see{prm:savebeam}
 %   \end{release}
 %   \begin{release}{4.1}{2013-05-21}
@@ -13041,7 +13142,7 @@
   labelstyle=,
   labelalign=c,
   labelref=relgrav,
-  ref@angle=0
+  ref@angle=180
 }%
 %    \end{macrocode}
 % External node
@@ -13675,7 +13776,14 @@
 \define@key[psset]{optexp}{raprismsize}{%
   \pst@checknum{#1}\POE@key@raprismsize
 }
-\psset[optexp]{raprismsize=1.5}
+\define@choicekey+[psset]{optexp}{raprismalign}[\val\nr]%
+  {auto,center}%
+  {\def\POE@key@raprismalign{#1}}%
+  {\PackageError{pst-optexp}{Unknown value '\val' for raprismalign}}%
+\psset[optexp]{%
+  raprismsize=1.5,
+  raprismalign=auto
+}
 %    \end{macrocode}
 % Prism
 %    \begin{macrocode}
@@ -15825,6 +15933,14 @@
 \def\oenode@TrefB#1{\oenode{@TrefB}{#1}}%
 %    \end{macrocode}
 % \end{macro}
+% \begin{macro}{\oenode@Origin}
+%   The origin of the component, available only for tripoles. Introduced
+%   to be able to compute the angle between AO and BO at later times
+%   (for \cs{rightangleprism} and \cs{optprism}.
+%    \begin{macrocode}
+\def\oenode@Origin#1{\oenode{Origin}{#1}}%
+%    \end{macrocode}
+% \end{macro}
 % \begin{macro}{\oenodeIfc}
 %   The node of the interface no. \#1 of component \#2. Only integer
 %   number, N or C are allowed. You should always use this e.g. to
@@ -16302,7 +16418,7 @@
     }%
     \expandafter\def\csname #2@ii\endcsname(##1)(##2)(##3)##4{%
       \addbefore@par{#3}%
-      \addafter@par{ref@angle=180,#1}%
+      \addafter@par{ref@angle=0,#1}%
       \begin@OptexpTripole
         \ifPOE@backlayer
           \POE@calcNodes{##1}{##2}{##3}%
@@ -16522,7 +16638,7 @@
   \fi
 }%
 \def\optcirculator@ii(#1)(#2)(#3)#4{%
-  \addafter@par{ref@angle=180}%
+  \addafter@par{ref@angle=0}%
   \begin@OptexpObj
     \POE@calcCircRefNodes{#1}{#2}{#3}%
     \POE@drawcomponent{optcirculator}{#4}
@@ -16677,9 +16793,64 @@
     calcNodes
     X@A Y@A}){\oenode@RefA{}}%
   \pnode(! \POE@dict{X@B Y@B}){\oenode@RefB{}}%
+  \pnode(#2){\oenode@Origin{}}%
 }\ignorespaces}%
 %    \end{macrocode}
 % \end{macro}
+%
+% \begin{macro}{\POE@calcAngle}
+%   Calculate the angle between the vectors A->O and B->0, which is
+%   needed by \cs{rightangleprism} and \cs{optprism}. Also calculate the
+%   angle difference between 'Winkelhalbierende' and
+%   'Seitenhalbierende', which is required for some corrections in
+%   \cs{rightangleprism}.
+%    \begin{macrocode}
+\def\POE@calcAngle{%
+  \POE@Verb{%
+    gsave
+      STV CP T
+      /N@\oenode@Origin{} @GetCenter 2 copy
+      /N@\oenodeRefA{} @GetCenter VecSub /ay ED /ax ED
+      /N@\oenodeRefB{} @GetCenter VecSub /by ED /bx ED
+%    \end{macrocode}
+% Winkelhalbierende (cx, cy)
+%    \begin{macrocode}
+      ax ay NormalizeVec bx by NormalizeVec VecAdd 
+      2 copy Pyth abs 1e-4 lt {
+%    \end{macrocode}
+% vectors a and b are antiparallel
+%    \begin{macrocode}
+        pop pop
+        ax ay 90 matrix rotate dtransform
+      } if
+      NormalizeVec 2 copy
+%    \end{macrocode}
+% Seitenhalbierende
+%    \begin{macrocode}
+      ax ay bx by VecAdd 
+      2 copy Pyth abs 1e-4 lt {
+%    \end{macrocode}
+% vectors a and b are parallel
+%    \begin{macrocode}
+        pop pop ax ay
+      } if
+      NormalizeVec 
+      4 copy 4 copy
+      DotProd Acos 5 1 roll Chirality mul 
+      /dOEangle exch def
+      ax ay Pyth bx by Pyth
+      2 copy dup mul exch dup mul add
+      ax bx sub ay by sub Pyth dup mul exch sub
+      3 1 roll -2 mul mul div Acos /OEangle exch def
+%    \end{macrocode}
+% project vector (ax, by) on the normal to the bisector
+%    \begin{macrocode}
+      neg exch ax ay \tx@UserCoor DotProd abs /@myht exch def
+    grestore
+  }%
+\ignorespaces}%
+%    \end{macrocode}
+% \end{macro}
 % 
 % \begin{macro}{\POE@regNodes}
 % If a macro needs only two points, they are equivalent to 
@@ -16717,14 +16888,10 @@
 %    \begin{macrocode}
 \def\POE@pnode@shiftedrot(#1)#2#3#4{%
   \pst@getcoor{#1}\POE@temp%
-  \pnode(!%
-    \POE@temp /YDiff ED /XDiff ED %
-    \pst@nodedict /N@#2 load GetCenter end /YShifted ED /XShifted ED
-    /rot@angle #4 \POE@key@labelrefangle\space add def
-    /XDiff@Rot rot@angle cos XDiff mul rot@angle sin YDiff mul add def
-    /YDiff@Rot rot@angle cos YDiff mul rot@angle sin XDiff mul sub def
-    XShifted XDiff@Rot add YShifted YDiff@Rot add neg \tx@UserCoor
-  ){#3}%
+  \pnode(! \POE@dict{
+    /N@#2 @GetCenter \POE@temp 
+    #4 \POE@key@labelrefangle\space add matrix rotate dtransform 
+    VecAdd \tx@UserCoor }){#3}%
   \psset[optexp]{ref@angle=0}
 }%
 %    \end{macrocode}
@@ -16913,7 +17080,7 @@
 % Define all free-ray tripoles
 %    \begin{macrocode}
 \newOptexpTripole{mirror}
-\newOptexpTripole[ref@angle=-135]{beamsplitter}
+\newOptexpTripole[ref@angle=45]{beamsplitter}
 \newOptexpTripole{optgrating}
 \def\optgrid{%
   \PackageWarning{pst-optexp}{%
@@ -16921,9 +17088,9 @@
     use \string\optgrating\space instead.}%
   \optgrating%
 }%
-\newOptexpTripole[ref@angle=-135]{pentaprism}
-\newOptexpTripole[ref@angle=-135]{rightangleprism}
-\newOptexpTripole[ref@angle=-135]{optprism}
+\newOptexpTripole[ref@angle=45]{pentaprism}
+\newOptexpTripole[ref@angle=45]{rightangleprism}
+\newOptexpTripole[ref@angle=45]{optprism}
 %    \end{macrocode}
 %
 % \begin{macro}{\optdipole}
@@ -16971,7 +17138,7 @@
     {\opttripole@ii(#1)(#2)(#3){#4}{}}%
 }%
 \def\opttripole@ii(#1)(#2)(#3)#4#5{%
-  \addafter@par{ref@angle=180}
+  \addafter@par{ref@angle=0}
   \begin@OptexpTripole
     \ifPOE@backlayer   
       \POE@calcNodes{#1}{#2}{#3}%
@@ -18212,11 +18379,9 @@
 % \begin{macro}{\optprism@ref}
 %    \begin{macrocode}
 \def\optprism@ref{%
-  \ifPOE@backlayer
-    \POE@Verb{/OEangle\the\POE@cnt\space OEangle def }%
-  \fi
-  \ifPOE@frontlayer
-    \POE@Verb{/OEangle OEangle\the\POE@cnt\space def }%
+  \POE@calcAngle
+  \ifx\POE@key@prismtype\POE@str@reflective
+    \edef\POE@key@labelrefangle{180}%
   \fi
 }%
 %    \end{macrocode}
@@ -18239,16 +18404,14 @@
     \fi
   }%
   \begingroup
-    \ifx\POE@key@prismtype\POE@str@reflective
-      \pst@def{ScreenCoor}< \pst@number\psyunit neg mul exch \pst@number\psxunit mul exch >
-    \fi
-    \pnode(! 0 \@hshift neg){\oenodeCenter{}}
+    \edef\POE@temp{\ifx\POE@key@prismtype\POE@str@reflective neg \fi}%
+    \pnode(! 0 \@hshift neg){\oenodeCenter{}}%
     \newOptexpComp{%
       {\@sz -0.6 mul \@ang tan mul \@hshift neg} 
-      {90 \@ang sub dup cos exch sin} 
+      {90 \@ang sub dup cos exch sin \POE@temp} 
       \@sz \@ang cos div dup -0.4 mul exch 0.6 mul trans {PlainIfc}
       {\@sz 0.6 mul \@ang tan mul \@hshift neg} 
-      {90 \@ang add dup cos exch sin} 
+      {90 \@ang add dup cos exch sin \POE@temp} 
       \@sz \@ang cos div dup -0.4 mul exch 0.6 mul trans {PlainIfc} 
 %    \end{macrocode}
 % Need to change the order of the two interfaces on the stack and add an
@@ -18256,7 +18419,7 @@
 %    \begin{macrocode}
       \ifx\POE@key@prismtype\POE@str@reflective
         12 6 roll
-        {0 \@sz -0.4 mul \@hshift sub } 
+        {0 \@sz 0.4 mul \@hshift sub } 
         {1 0} \@ang tan \@sz mul dup neg exch refl {PlainIfc}
         12 6 roll
       \fi
@@ -18283,9 +18446,9 @@
     \fi
   }%
   \edef\POE@temp{\ifx\POE@key@prismtype\POE@str@reflective -1 mul \fi}%
-  \pspolygon(! \@sz neg \@altan mul \@sz -0.4 mul \@hshift sub \POE@temp)
-            (! \@sz \@altan mul \@sz -0.4 mul \@hshift sub \POE@temp)
-            (! 0 \@sz 0.6 mul \@hshift sub \POE@temp)
+  \pspolygon(! \@sz neg \@altan mul \@sz -0.4 mul \POE@temp \@hshift sub)
+            (! \@sz \@altan mul \@sz -0.4 mul \POE@temp \@hshift sub)
+            (! 0 \@sz 0.6 mul \POE@temp \@hshift sub)
 }%
 %    \end{macrocode}
 % \end{macro}
@@ -18293,33 +18456,23 @@
 % \subsubsection{rightangleprism}
 %
 % \begin{macro}{\rightangleprism@ref}
+%   All tripole components are aligned such, that the x-axis is normal
+%   to the angle bisector (Winkelhalbierende), but for the right angle
+%   prism the x-axis must be oriented normal to the bisector
+%   (Seitenhalbierende). So we must correct for the difference in both
+%   orientations, which is stored in dOEangle.
 %    \begin{macrocode}
 \def\rightangleprism@ref{%
-  \ifPOE@backlayer
-    \POE@Verb{/OEangle\the\POE@cnt\space OEangle def }%
-  \fi
-  \ifPOE@frontlayer
-    \POE@Verb{/OEangle OEangle\the\POE@cnt\space def }%
-  \fi
-  \POE@setref{%
-    OEangle 0.5 mul
-    { x sin modA mul } 
-    { OEangle x sub sin modB mul }
-    tx@EcldDict begin
-%    \end{macrocode}
-% Need to redefine /ZeroEq locally, because 1e-6 is too low for
-% e.g. \cs{rightangleprism(2,2)(4,1)(2,0)}, which oscillates around \pm
-% 1.7e-6.
-%    \begin{macrocode}
-      10 dict begin
-        /ZeroEq { abs 5e-6 lt } bind def
-        NewtonSolving pop
-      end
-    end
-    /@htA exch def
-    OEangle 0.5 mul exch sub /dOEangle exch def
+  \POE@calcAngle
+  \POE@Verb{%
+    /@htA @myht def
     /@OEtrafo {dOEangle matrix rotate dtransform } bind def
   }%
+%    \end{macrocode}
+% Correct also the label reference angle for nonsymmetric reference nodes.
+%    \begin{macrocode}
+  \let\POE@temp\POE@key@labelrefangle
+  \edef\POE@key@labelrefangle{\POE@temp \POE@dict{dOEangle add} }%
 }%
 %    \end{macrocode}
 % \end{macro}
@@ -18327,17 +18480,23 @@
 % \begin{macro}{\rightangleprism@nodes}
 %    \begin{macrocode}
 \def\rightangleprism@nodes{%
-  \edef\@sz{\POE@key@raprismsize\space}%
-  \edef\@ht{\POE@dict{OEangle 0.5 mul sin modA mul} }%
+  \edef\@sz{\POE@key@raprismsize\space 0.5 mul }%
+  \POE@Verb{%
+    \ifx\POE@key@raprismalign\POE@str@auto
+      /@corrshift {} bind def
+    \else
+      /@corrshift {@htA sub \@sz 0.5 mul add } bind def%
+    \fi
+  }%
   \newOptexpComp{%
-    {@htA neg @htA \@sz 0.5 mul sub @OEtrafo} {1 0 @OEtrafo} 
-    @htA \@sz 0.5 mul sub @htA trans {PlainIfc}
-    {@htA neg 0 @OEtrafo} {1 1 @OEtrafo} 
-    @htA 2 sqrt mul dup \@sz 2 sqrt div sub exch refl {PlainIfc}
-    {@htA 0 @OEtrafo} {-1 1 @OEtrafo} 
-    @htA 2 sqrt mul dup \@sz 2 sqrt div sub exch refl {PlainIfc}
-    {@htA dup \@sz 0.5 mul sub @OEtrafo} {1 0 @OEtrafo} 
-    @htA neg \@sz 0.5 mul @htA sub trans {PlainIfc} 
+    {@htA neg @htA \@sz sub @corrshift @OEtrafo} {1 0 @OEtrafo} 
+    @htA \@sz sub @htA trans {PlainIfc}
+    {@htA neg 0 @corrshift @OEtrafo} {1 1 @OEtrafo} 
+    @htA 2 sqrt mul dup \@sz 0.5 sqrt div sub exch refl {PlainIfc}
+    {@htA 0 @corrshift @OEtrafo} {-1 1 @OEtrafo} 
+    @htA 2 sqrt mul dup \@sz 0.5 sqrt div sub exch refl {PlainIfc}
+    {@htA dup \@sz sub @corrshift @OEtrafo} {1 0 @OEtrafo} 
+     @htA neg \@sz @htA sub trans {PlainIfc} 
     \POE@key@n 
   }%
 \ignorespaces}%
@@ -18348,9 +18507,15 @@
 %    \begin{macrocode}
 \def\rightangleprism@comp{%
   \edef\@sz{\POE@key@raprismsize\space 0.5 mul }%
-  \pspolygon(!\POE@dict{\@sz neg @htA \@sz sub @OEtrafo})
-            (!\POE@dict{\@sz @htA \@sz sub @OEtrafo})
-            (! 0 \POE@dict{@htA @OEtrafo})%
+  \ifx\POE@key@raprismalign\POE@str@auto
+    \pspolygon(!\POE@dict{\@sz neg @htA \@sz sub @OEtrafo})
+              (!\POE@dict{\@sz @htA \@sz sub @OEtrafo})
+              (! 0 \POE@dict{@htA @OEtrafo})%
+  \else
+    \pspolygon(!\POE@dict{\@sz \@sz -0.5 mul @OEtrafo})%
+              (!\POE@dict{\@sz neg \@sz -0.5 mul @OEtrafo})%
+              (!\POE@dict{0 \@sz 0.5 mul @OEtrafo})
+  \fi
 \ignorespaces}%
 %    \end{macrocode}
 % \end{macro}
@@ -19135,7 +19300,7 @@
     {\elecmixer@ii(#1)(#2)(#3){}}%
 }%
 \def\elecmixer@ii(#1)(#2)(#3)#4{%
-  \addafter@par{ref@angle=180}%
+  \addafter@par{ref@angle=0}%
   \begin@OptexpObj
     \POE@calcCircRefNodes{#1}{#2}{#3}%
     \POE@drawcomponent{elecmixer}{#4}
@@ -19621,37 +19786,25 @@ tx@OptexpDict begin
 % 
 % \begin{macro}{calcNodes}
 %   Calculate the reference node coordinates for reflective components and
-%   stores them as \PSvar{X@A}, \PSvar{Y@A}, \PSvar{X@B} and \PSvar{Y@B}. Some
-%   other values (\PSvar{modA}, \PSvar{modB}, and \PSvar{OEangle}) are also
-%   stored for some special components
+%   stores them as \PSvar{X@A}, \PSvar{Y@A}, \PSvar{X@B} and \PSvar{Y@B}.
 % \begin{pssyntax}
-%   \PSvar{XB} \PSvar{YB} \PSvar{XA} \PSvar{YA} \PSvar{XG} \PSvar{YG} \PSop{calcNodes}
+%   \PSvar{XA} \PSvar{YA} \PSvar{XB} \PSvar{YB} \PSvar{XG} \PSvar{YG} \PSop{calcNodes}
 % \end{pssyntax}
 %    \begin{macrocode}
 /calcNodes {
   (calcNode) DebugBegin
   /YG exch def /XG exch def
-  /ay YG 3 -1 roll sub def
-  /ax XG 3 -1 roll sub def
   /by exch YG sub def
   /bx exch XG sub def
-  /a ax ay Pyth def
-%    \end{macrocode}
-% Used by \cs{rightangleprism}.
-%    \begin{macrocode}
-  /modA a def
-  /b bx by Pyth def
-  /modB b def
-  /cx ax a div bx b div add def
-  /cy ay a div by b div add def
-  /c@tmp cx cy Pyth def
+  /ay YG 3 -1 roll sub def
+  /ax XG 3 -1 roll sub def
+  ax ay NormalizeVec bx by NormalizeVec VecAdd
+  2 copy Pyth abs 1e-4 lt { 
+    pop pop ax ay -90 matrix rotate dtransform
+  } if
+  /cy ED /cx ED
   /c ax bx add ay by add Pyth def
 %    \end{macrocode}
-% Used by \cs{rightangleprism} and \cs{optprism}.
-%    \begin{macrocode}
-  /OEangle c dup mul a dup mul sub b dup mul sub 
-             -2 a b mul mul div Acos def
-%    \end{macrocode}
 % If $c=0$, then set the coordinates of the vector manually depending whether
 % \PSvar{a} and \PSvar{b} are parallel or antiparallel.
 %    \begin{macrocode}
@@ -19666,12 +19819,10 @@ tx@OptexpDict begin
       /cx ay def
       /cy ax neg def
     } ifelse
-    /c@tmp a def
   } if
-  /X@A XG cx c@tmp div add def
-  /Y@A YG cy c@tmp div add def
-  /X@B XG cx c@tmp div sub def
-  /Y@B YG cy c@tmp div sub def
+  cx cy NormalizeVec 2 copy
+  XG YG VecAdd /Y@A ED /X@A ED
+  XG YG 4 2 roll VecSub /Y@B ED /X@B ED
 %    \end{macrocode}
 % Test the chirality (the order) of the input points. Input angles $> 90$\textdegree
 % don't make sense, in this case we exhange the calculated reference nodes.
@@ -19682,7 +19833,6 @@ tx@OptexpDict begin
     /Y@A Y@B def
     /X@B exch def
     /Y@B exch def
-    modA modB /modA exch def /modB exch def
   } if
   DebugEnd
 } bind def
@@ -21563,6 +21713,18 @@ tx@OptexpDict begin
 } bind def
 %    \end{macrocode}
 % \end{macro}
+%
+% \begin{macro}{VecSub}
+% Subtraction of two vectors.
+% \begin{pssyntax}
+%   \PSvar{Xa Ya Xb Yb} \PSop{VecSub} \PSvar{Xa-Xb Ya-Yb}
+% \end{pssyntax}
+%    \begin{macrocode}
+/VecSub {
+    neg 3 -1 roll add 3 1 roll neg add exch
+} bind def
+%    \end{macrocode}
+% \end{macro}
 % 
 % \begin{macro}{VecScale}
 % Scale a vector by a factor \PSvar{fac}.
-- 
cgit v1.2.3

