# Cut off part of PSTricks parallelogram if

First: I have also posted this question at the LaTeX Community a few days ago but I have not got any answer.

Consider the following MWE, illustrating rays of light coming from the Sun through the Oculus in the Pantheon, Rome:

\documentclass{article}

\usepackage[locale=DE]{siunitx}
\usepackage{expl3}

\ExplSyntaxOn
\cs_new_eq:NN
\calculate
\fp_eval:n
\ExplSyntaxOff

\begin{document}

\def\vinkelA{12 }   % Width of the Oculus
\def\vinkelB{71 }   % Angle of the Sun's rays
\def\faktor{\calculate{1/3} }
\def\vinkelC{\calculate{90-\vinkelA} }
\def\vinkelD{\calculate{90+\vinkelA} }
\def\vinkelE{\calculate{180+\vinkelC} }
\def\vinkelF{\calculate{180+\vinkelD} }
\def\vinkelG{\calculate{180-\vinkelB} }
\def\vinkelH{\calculate{180+\vinkelG} }
\begin{figure}
\centering
\begin{pspicture}(44,50)
\psset{unit=0.5cm,linecolor=red}
\pnode(0,0){A}
\psset{linestyle=none,linecolor=black,dotsep=2pt}
\psRelLine[angle=\vinkelF](E)(B){1}{P1}
\psRelLine[angle=\vinkelE](E)(B){1}{P2}
\psRelLine[angle=\vinkelG](P1)(P2){1}{L1}
\psRelLine[angle=\vinkelH,linestyle=dotted](P2)(P1){1}{L2}
\psRelLine[angle=\vinkelG](P2)(P1){1 \vinkelA cos add 2 \vinkelA sin mul \vinkelB sin mul div}{L3}
\psParallelLine(L2)(L3)(L1){1}{L4}
\pspolygon[fillstyle=solid,fillcolor=yellow](L1)(L2)(L3)(L4)
\pcline[linestyle=dotted](T1)(T2)
\psline[linestyle=solid,linecolor=red](C)(D)(A)(B)
\end{pspicture}
\end{figure}

\end{document}


I would like to cut off the yellow parallelogram if it reaches the left or right, vertical part of the closed red curve, i.e., if the rays of light hit the walls. How do I do this?

P.S. I have no experience at all using TikZ, so if I am to understand a possible answer, TikZ is not the way to go. That said, I will not mind a TikZ answer but then the code has to be complete enough for me to copy directly.

-

A quick solution is to clip the yellow paralellogram with the red rectangle for vinkelB angle greater than approx. 45 degrees. Otherwise you can include the full dome path for clipping since the idea is the same.

\documentclass{article}

\usepackage[locale=DE]{siunitx}
\usepackage{expl3}

\ExplSyntaxOn
\cs_new_eq:NN
\calculate
\fp_eval:n
\ExplSyntaxOff

\begin{document}

\def\vinkelA{12 }   % Width of the Oculus
\def\vinkelB{60 }   % Angle of the Sun's rays
\def\faktor{\calculate{1/3} }
\def\vinkelC{\calculate{90-\vinkelA} }
\def\vinkelD{\calculate{90+\vinkelA} }
\def\vinkelE{\calculate{180+\vinkelC} }
\def\vinkelF{\calculate{180+\vinkelD} }
\def\vinkelG{\calculate{180-\vinkelB} }
\def\vinkelH{\calculate{180+\vinkelG} }

\begin{pspicture}
\psset{unit=0.5cm,linecolor=red}
\pnode(0,0){A}
\psset{linestyle=none,linecolor=black,dotsep=2pt}
\psRelLine[angle=\vinkelF](E)(B){1}{P1}
\psRelLine[angle=\vinkelE](E)(B){1}{P2}
\psRelLine[angle=\vinkelG](P1)(P2){1}{L1}
\psRelLine[angle=\vinkelH,linestyle=dotted](P2)(P1){1}{L2}
\psRelLine[angle=\vinkelG](P2)(P1){1 \vinkelA cos add 2 \vinkelA sin mul \vinkelB sin mul div}{L3}
\psParallelLine(L2)(L3)(L1){1}{L4}
\pspolygon[fillstyle=solid,fillcolor=yellow](L1)(L2)(L3)(L4)
\end{psclip}
\pcline[linestyle=dotted](T1)(T2)
\psline[linestyle=solid,linecolor=red](C)(D)(A)(B)
\end{pspicture}

\end{document}


Also a Tikz solution, if you don't want the shading just remove the preaction option inside the clip path.

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\usepackage[locale=DE]{siunitx}

\begin{document}

\def\vinkelA{15.0}   % Width of the Oculus
\def\vinkelB{65}     % Angle of the Sun's rays
\pgfmathsetmacro\faktor{1/3}
\begin{tikzpicture}
\coordinate(A) at (0,0);
\coordinate(F) at ($(E) + (90+\vinkelA:\RelRadius cm)$);
\coordinate(G) at ($(E) + (90-\vinkelA:\RelRadius cm)$);

\begin{scope}
\draw[shorten <=-10 cm,yellow,line width=\oculus cm*0.9*sin(\vinkelB)]
($(F)!0.5!(G)$) -- ++(-\vinkelB:30 cm);
\end{scope}

\draw[red,ultra thick] (F) arc (90+\vinkelA:180:\RelRadius cm)
|- (D) -- (C) arc (0:90-\vinkelA:\RelRadius cm);

\draw[shorten <=-2 cm,yellow,line width=\oculus cm*0.9*sin(\vinkelB)]
($(F)!0.5!(G)$) --++(180-\vinkelB:2cm);

\draw[densely dotted] (A |-F) -- (D|-G) (G) -- ++(180-\vinkelB:2cm);
\draw[latex-latex] (G) ++(180-\vinkelB:10 mm) arc (180-\vinkelB:180:10 mm);
\node at ($(G)+(180-0.5*\vinkelB:1.3cm)$) {$\vinkelB^\circ$};
\end{tikzpicture}

\end{document}


-
 This is very impressive! However... PSTricks code: If the rays hit the curved part (i.e., the dome) the rays continut outside the dome. TikZ code: There is a space between the incoming rays and the edge of the Oculus... Furthermore, both set of code 'only' work if the rays hit the right side of the wall/dome. – Svend Tveskæg Oct 14 '12 at 17:24 @SvendMortensen Yes, I've tried to explain that in the PSTricks part you need to clip with the whole dome path. For TikZ you can have it on the left wall too. Try setting vinkelB to 120 and also make both 0.9 to 0.95 – percusse Oct 14 '12 at 17:31 I saw your commant about the PSTricks path just after the eidting periode for my comment expired; sorry. TikZ: Sweet. P.S. Any chance I can make you correct the PSTricks code to include the full dome path. I cannot figure out how to do that (even though it is probably rather trivial). – Svend Tveskæg Oct 14 '12 at 17:47 Come to think of it, I still do not get this full path thing. I thought that pscharclip from the pst-text package might be the way to go but I cannot get it to work. – Svend Tveskæg Oct 14 '12 at 18:46 Yes I couldn't manage to do it too. Looks like we have to ask @Herbert for a nontrivial path clip. As TikZ solution uses the same path twice probably one needs to do the same in PSTricks too. – percusse Oct 14 '12 at 18:51

there is no need for using the expl3 packages ...

\documentclass[pstricks]{standalone}
\usepackage[locale=DE]{siunitx}

\begin{document}
\def\faktor{0.3333}

\multido{\iA=10+5}{30}{%
\def\vinkelA{12 }   % Width of the Oculus
\def\vinkelB{\iA\space }   % Angle of the Sun's rays
\psset{unit=0.5cm,linecolor=red}
\begin{pspicture}(-0.2,-0.2)(15,17)
\pnode(0,0){A}
\pscustom[linewidth=3pt,dimen=inner]{%
\psset{linestyle=none,linecolor=black,dotsep=2pt}
\psRelLine[angle=!270 \vinkelA sub](E)(B){1}{P2}
\psRelLine[angle=!180 \vinkelB sub](P1)(P2){1}{L1}
\psRelLine[angle=!360 \vinkelB sub,linestyle=dotted](P2)(P1){1}{L2}
\psRelLine[angle=!180 \vinkelB sub](P2)(P1){1 \vinkelA cos add 2 \vinkelA sin mul \vinkelB sin mul div}{L3}
\psParallelLine(L2)(L3)(L1){1}{L4}
\begin{psclip}{\pscustom[linestyle=none,fillstyle=solid,fillcolor=blue!20]{%
\pspolygon[fillstyle=solid,fillcolor=yellow](L1)(L2)(L3)(L4)
\end{psclip}
\pspolygon[fillstyle=solid,fillcolor=yellow](L1)(P1)(P2)(L2)
\pcline[linestyle=dotted](T1)(T2)
\end{pspicture}}

\end{document}


and a simpler solution with setting the origin of the coordinate system into the middle and uses the linewidth for the yellow sun beam:

\documentclass[pstricks]{standalone}
\usepackage[locale=DE]{siunitx}

\begin{document}
\def\faktor{0.3333}
\def\vinkelA{12}   % Width of the Oculus
\makeatletter
\pst@getsinandcos{\vinkelA}
\pstFPmul\MaxLW{2}{\MaxLW}

\multido{\iA=10+5}{16}{% % Angle of the Sun's rays
\psset{unit=0.5cm}
\pst@getsinandcos{\iA}
\pstFPmul\RelLW{\MaxLW}{\pst@sin}
\pnode(0,0){C}
\pcline[linecolor=yellow,linewidth=\RelLW,nodesepB=-8,nodesepA=-1]%
(0,0)(!-1 \iA\space neg Tan neg)}
\begin{psclip}{%
\pscustom[linewidth=2pt,linecolor=red,fillstyle=solid,fillcolor=blue!20]{%
\psline(B)(A)(D)
\pcline[linecolor=yellow,linewidth=\RelLW,nodesep=-4]%
(0,0)(!\RelRadius\space dup \iA\space neg Tan mul )}
\end{psclip}

 Sweet! I wish I could accept both answers. When I compile, I get the error "! Undefined control sequence. \c@lor@to@ps l.39 \end{pspicture}}" Do you know why? – Svend Tveskæg Oct 15 '12 at 7:55 sure, you used pdflatex without package auto-pst-pdf or better xelatex – Herbert Oct 15 '12 at 9:33 I used pdflatex with auto-pst-pdf just as you expected. However, when I use xelatex it takes more than a minut to compile (but when it is done, it is okay). – Svend Tveskæg Oct 15 '12 at 14:10 Never mind, I figured it out. Thank you very much for helping. – Svend Tveskæg Oct 15 '12 at 16:10