# How to customize transmission grating in pst-optexp?

My current working example:

\documentclass[preview,border=20pt]{standalone}
\usepackage{pst-optexp}
\usepackage{pst-node}

\begin{document}
\begin{pspicture}[showgrid](2, 2)
\pnodes(0,1){A}
\pnodes(2,1){B}
\pnodes(1,1){C}
\begin{optexp}
\transmissiongrating[angle=180,gratingcount=10,gratingwidth=0.8,gratingheight=0.07,gratingdepth=0.03,gratingtype=binary](A)(C)(B)
\optbox[abspos=1.5, optboxwidth=0.1,optboxheight=0.8](A)(B)
\addtopsstyle{Beam}{linestyle=none, fillstyle=solid, fillcolor=green!70!black, beaminside=false}
\drawwidebeam[beamwidth=0.4,beamdiv=4](A){1-2}
\end{optexp}
\end{pspicture}
\end{document}


I would like to do:

• A Fresnel-lens like binary transmission grating in package pst-optexp. Ray-tracking is not necessary.
• Keep the beam-drawing out of this grating.

Here is a sketch for my wish:

Thanks for any help and suggestions.

Such special gratings aren't supported out-of-the-box. However, you can use \optdipole to use any kind of object as component:

\documentclass[preview,border=20pt]{standalone}
\usepackage{pst-optexp}

\begin{document}
\begin{pspicture}[showgrid](2, 2)
\pnodes(0,1){A}
\pnodes(2,1){B}
\begin{optexp}
\optdipole(A)(B){%
\pspolygon[fillstyle=solid,fillcolor=white]
(0.05,0.5)(-0.05,0.5)(-0.05,0.45)(0,0.45)(0,0.35)(-0.05,0.35)(-0.05,0.2)(0,0.2)(0,0.15)(-0.05,0.15)
(-0.05,-0.15)(0,-0.15)(0,-0.2)(-0.05,-0.2)(-0.05,-0.35)(0,-0.35)(0,-0.45)(-0.05,-0.45)(-0.05,-0.5)
(0.05,-0.5)
}
\optbox[abspos=1.5, optboxwidth=0.1,optboxheight=0.8](A)(B)
\addtopsstyle{Beam}{linestyle=none, fillstyle=solid, fillcolor=green!70!black, beaminside=false}
\drawwidebeam[beamwidth=0.4,beamdiv=4](A){1-2}
\end{optexp}
\end{pspicture}
\end{document}


If you need that component more often, you can define it with \newpsobject and parameter optdipolecomp:

\documentclass[preview,border=20pt]{standalone}
\usepackage{pst-optexp}
\def\fresnelgratingcomp{%
\pspolygon[fillstyle=solid,fillcolor=white]
(0.05,0.5)(-0.05,0.5)(-0.05,0.45)(0,0.45)(0,0.35)(-0.05,0.35)(-0.05,0.2)(0,0.2)(0,0.15)(-0.05,0.15)
(-0.05,-0.15)(0,-0.15)(0,-0.2)(-0.05,-0.2)(-0.05,-0.35)(0,-0.35)(0,-0.45)(-0.05,-0.45)(-0.05,-0.5)
(0.05,-0.5)}
\newpsobject{fresnelgrating}{optdipole}{optdipolecomp={\fresnelgratingcomp}}
\begin{document}

\begin{pspicture}[showgrid](2, 2)
\pnodes(0,1){A}
\pnodes(2,1){B}
\begin{optexp}
\fresnelgrating(A)(B)
\optbox[abspos=1.5, optboxwidth=0.1,optboxheight=0.8](A)(B)
\addtopsstyle{Beam}{linestyle=none, fillstyle=solid, fillcolor=green!70!black, beaminside=false}
\drawwidebeam[beamwidth=0.4,beamdiv=4](A){1-2}
\end{optexp}
\end{pspicture}
\end{document}

• One more small question: How to change the size of the new object? Follow your manual, simply writing \fresnelgrating[optdipolesize=2 0.8](A)(B) but does not change its size. – WDC Dec 11 '17 at 0:18