Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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{auto-pst-pdf,pst-eucl,pstricks-add}
\usepackage[locale=DE]{siunitx}
\usepackage{expl3}

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

\begin{document}

\def\radius{21.65 } % Radius of the dome
\def\vinkelA{12 }   % Width of the Oculus
\def\vinkelB{71 }   % Angle of the Sun's rays
\def\faktor{\calculate{1/3} }
\def\RelRadius{\calculate{\faktor*\radius} }
\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}
   \pnode(!0 \RelRadius){B}
   \pnode(!2 \RelRadius mul \RelRadius){C}
   \pnode(!2 \RelRadius mul 0){D}
   \pnode(!\RelRadius \RelRadius){E}
   \psarc(E){\RelRadius}{0}{\vinkelC}
   \psarc(E){\RelRadius}{\vinkelD}{180}
  \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)
   \pnode(!0 1 \vinkelA cos add \RelRadius mul){T1}
   \pnode(!2 \RelRadius mul 1 \vinkelA cos add \RelRadius mul){T2}
   \pcline[linestyle=dotted](T1)(T2)
   \pstMarkAngle[linestyle=solid,MarkAngleRadius=0.8,LabelSep=1.5,arrows=<->]{L2}{P2}{T1}{\footnotesize{\SI{\vinkelB}{\degree}}}
   \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.

share|improve this question
add comment

2 Answers 2

up vote 7 down vote accepted

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{pst-eucl,pstricks-add}
\usepackage[locale=DE]{siunitx}
\usepackage{expl3}

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

\begin{document}

\def\radius{21.65 } % Radius of the dome
\def\vinkelA{12 }   % Width of the Oculus
\def\vinkelB{60 }   % Angle of the Sun's rays
\def\faktor{\calculate{1/3} }
\def\RelRadius{\calculate{\faktor*\radius} }
\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}
   \pnode(!0 \RelRadius){B}
   \pnode(!2 \RelRadius mul \RelRadius){C}
   \pnode(!2 \RelRadius mul 0){D}
   \pnode(!\RelRadius \RelRadius){E}
   \psarc(E){\RelRadius}{0}{\vinkelC}
   \psarc(E){\RelRadius}{\vinkelD}{180}
  \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}
   \begin{psclip}{\pspolygon(A)(D)(!2 \RelRadius mul \radius)(0,\radius)}
   \pspolygon[fillstyle=solid,fillcolor=yellow](L1)(L2)(L3)(L4)
   \end{psclip}
   \pnode(!0 1 \vinkelA cos add \RelRadius mul){T1}
   \pnode(!2 \RelRadius mul 1 \vinkelA cos add \RelRadius mul){T2}
   \pcline[linestyle=dotted](T1)(T2)
   \pstMarkAngle[linestyle=solid,MarkAngleRadius=0.8,LabelSep=1.5,arrows=<->]{L2}{P2}{T1}{\footnotesize{\SI{\vinkelB}{\degree}}}
   \psline[linestyle=solid,linecolor=red](C)(D)(A)(B)
  \end{pspicture}


\end{document}

enter image description here

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\radius{8.66}    % Radius of the dome
\def\vinkelA{15.0}   % Width of the Oculus
\def\vinkelB{65}     % Angle of the Sun's rays
\pgfmathsetmacro\faktor{1/3}
\pgfmathsetmacro\RelRadius{\faktor*\radius}
\pgfmathsetmacro\oculus{2*\RelRadius/tan(90-\vinkelA)}
\begin{tikzpicture}
   \coordinate(A) at (0,0);
   \coordinate(B) at (0,\RelRadius cm);
   \coordinate(C) at (2*\RelRadius cm,\RelRadius cm);
   \coordinate(D) at (2*\RelRadius cm,0);
   \coordinate(E) at (\RelRadius cm,\RelRadius cm);
   \coordinate(F) at ($(E) + (90+\vinkelA:\RelRadius cm)$);
   \coordinate(G) at ($(E) + (90-\vinkelA:\RelRadius cm)$);

\begin{scope}
    \clip[preaction={top color=gray,bottom color=yellow!15}] % Shading
    (F) arc (90+\vinkelA:180:\RelRadius cm)|- (D) -- (C) arc (0:90-\vinkelA:\RelRadius cm);
    \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}

enter image description here enter image description here

share|improve this answer
    
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
show 6 more comments

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

\documentclass[pstricks]{standalone}
\usepackage{pst-eucl,pst-grad,pstricks-add}
\usepackage[locale=DE]{siunitx}

\begin{document}
\def\radius{21.65} % Radius of the dome
\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
\pstFPmul\RelRadius\faktor{\radius}
\psset{unit=0.5cm,linecolor=red}
\begin{pspicture}(-0.2,-0.2)(15,17)
   \pnode(0,0){A}
   \pnode(!0 \RelRadius){B}
   \pnode(!2 \RelRadius\space mul \RelRadius){C}
   \pnode(!2 \RelRadius\space mul 0){D}
   \pnode(!\RelRadius\space dup){E}
   \pscustom[linewidth=3pt,dimen=inner]{%
     \psline(A)(D)\psarc(E){\RelRadius}{0}{180}\psline(B)(A)}
   \psset{linestyle=none,linecolor=black,dotsep=2pt}
   \psRelLine[angle=!270 \vinkelA add ](E)(B){1}{P1}
   \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]{%
     \psline(A)(D)(!\RelRadius\space dup add \RelRadius)
     \psarc(E){\RelRadius}{0}{180}\psline(B)(A)}}
     \pspolygon[fillstyle=solid,fillcolor=yellow](L1)(L2)(L3)(L4)
   \end{psclip}
   \pspolygon[fillstyle=solid,fillcolor=yellow](L1)(P1)(P2)(L2)
   \pnode(!0 1 \vinkelA cos add \RelRadius\space mul){T1}
   \pnode(!2 \RelRadius\space mul 1 \vinkelA cos add \RelRadius\space mul){T2}
   \pcline[linestyle=dotted](T1)(T2)
   \pstMarkAngle[linestyle=solid,MarkAngleRadius=0.8,LabelSep=1.5,arrows=<->]{L2}{P2}{T1}{\footnotesize{\SI{\vinkelB}{\degree}}}
\end{pspicture}}

\end{document}

enter image description here

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{pstricks-add}
\usepackage[locale=DE]{siunitx}

\begin{document}
\def\radius{21.65} % Radius of the dome
\def\faktor{0.3333}
\def\vinkelA{12}   % Width of the Oculus
\makeatletter
\pst@getsinandcos{\vinkelA}
\pstFPmul\RelRadius\faktor{\radius}
\pstFPmul\MaxLW\RelRadius\pst@sin
\pstFPmul\MaxLW{2}{\MaxLW}

\multido{\iA=10+5}{16}{% % Angle of the Sun's rays
\psset{unit=0.5cm}
\begin{pspicture}(-\RelRadius,-\RelRadius)(\RelRadius,10)
  \pst@getsinandcos{\iA}
  \pstFPmul\RelLW{\MaxLW}{\pst@sin}
  \pnode(-\RelRadius,-\RelRadius){A}
  \pnode(-\RelRadius,0){B}
  \pnode(0,0){C}
  \pnode(\RelRadius,-\RelRadius){D}
  \pnode(!0 \RelRadius\space \vinkelA\space cos mul){T1}
  \rput(!0 \RelRadius\space \vinkelA\space cos mul){%
        \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]{%
    \psarc(C){\RelRadius}{!90 \vinkelA\space add}{180}
    \psline(B)(A)(D)
    \psarc(C){\RelRadius}{0}{!90 \vinkelA\space sub}}}
    \rput(!0 \RelRadius\space \vinkelA\space cos mul){%
        \pcline[linecolor=yellow,linewidth=\RelLW,nodesep=-4]%
       (0,0)(!\RelRadius\space dup \iA\space neg Tan mul )}
  \end{psclip}
  \psline[linestyle=dotted]({-\RelRadius,0}|T1)({\RelRadius,0}|T1)
  \rput(!\RelRadius\space 90 \vinkelA\space sub PtoC){%
    \pswedge(0,0){1}{!180 \iA\space sub}{180}
    \uput{1}[!180 \iA\space 2 div sub](0,0){\footnotesize\SI{\iA}{\degree}}
    \psline[linestyle=dotted](0,0)(!3 180 \iA\space sub PtoC)
  }
\end{pspicture}}

\end{document}

enter image description here

share|improve this answer
    
Sweet! I wish I could accept both answers. When I compile, I get the error "! Undefined control sequence. <recently read> \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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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