4

Consider the following code (which is almost the same as this):

\documentclass{article}

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

\def\radius{21.65}
\def\vinkelA{12 }
\pstFPdiv\faktor{1}{3}
\pstFPmul\faktorB{\radius}{\faktor}
\pstFPadd\faktorC{\faktorB}{0.05}
\pstFPadd\faktorD{\faktorB}{2.95}
\makeatletter
  \pst@getsinandcos{\vinkelA}
  \pstFPmul\RelRadius\faktor{\radius}
  \pstFPmul\PSTRadius{1.02}\RelRadius
  \pstFPmul\MaxLW\RelRadius\pst@sin
  \pstFPmul\MaxLW{2}{\MaxLW}
  \def\PolyLine{%
    \psarc(C){\RelRadius}{!90 \vinkelA add}{180}
    \psline(B)(A)(D)
    \psarc(C){\RelRadius}{0}{!90 \vinkelA sub}
  }

\def\light#1{% Sun beams.
\psset{
  unit=0.7
}
 \begin{pspicture}(-\faktorC,-\faktorC)(\faktorC,\faktorD)
   \pst@getsinandcos{#1}
     \ifnum #1 = 90 \let\RelLW\MaxLW
   \else
     \ifnum #1 > 90 \pstFPmul\RelLW{\MaxLW}{\pst@cos}
     \else          \pstFPmul\RelLW{\MaxLW}{\pst@sin}
     \fi
   \fi
   \pnode(-\RelRadius,-\RelRadius){A}
   \pnode(-\RelRadius,0){B}
   \pnode(0,0){C}
   \pnode(\RelRadius,-\RelRadius){D}
   \pnode(!0 \RelRadius\space \vinkelA cos mul){T1}
   % Filling
   \pscustom[
     linewidth=2pt,
     linecolor=red,
     fillstyle=gradient,
     gradbegin=blue!5,
     gradmidpoint=1,
     gradend=blue!35
   ]{\PolyLine}
   \begin{psclip}{% Clipping.
     \pscustom[
       linestyle=none,
       dimen=inner
     ]{%
     \PolyLine
     \psline(\RelRadius,\RelRadius)(!\RelRadius\space dup 3 add)%
            (!\RelRadius\space dup neg exch 3 add)(-\RelRadius,\RelRadius)
     }
   }
   \rput(!0 \RelRadius\space \vinkelA cos mul){%
     \pcline[
       linecolor=yellow,
       linewidth=\RelLW,
       nodesep=-\radius
     ](0,0)(!#1 dup 90 ne {-1 exch neg Tan neg} {0 -1} ifelse)}
   \end{psclip}
   \pscustom[
     linewidth=2pt,
     linecolor=red
   ]{\PolyLine}% Better clipping.
   \psline[
     linestyle=dotted
   ]({-\RelRadius,0}|T1)({\RelRadius,0}|T1)
   \rput(!\RelRadius\space 90 \vinkelA sub PtoC){%
     \pswedge(0,0){1}{!180 #1 sub}{180}
     \uput{1}[!180 #1 2 div sub](0,0){\footnotesize \SI{#1}{\degree}}
     \psline[
       linestyle=dotted
     ](0,0)(!3 180 #1 sub PtoC)
   }
 \end{pspicture}
}

\begin{document}

\begin{animateinline}[poster=first,controls,palindrome]{2}
  \multiframe{121}{iA=30+1}{\light{\iA}}
\end{animateinline}

\end{document}

output

I don't like the way red curve 'hits' the yellow area; how do I improve this? (I'm not exactly sure what I want but I'll tell if the answer(s) given is/are what I'm looking for.)

P.S. Feel free to add more tags.

2
  • you could draw the red lines first, and then the yellow thing on top? too simplistic? :)
    – cmhughes
    Sep 21, 2013 at 15:30
  • @cmhughes It could be good! :) My problem is that I put the code for the red curve in the wrong place; the upper part of the yellow parallellogram disappears when I rearrange the code. Can I get you to rearrange the code correctly for me in an answer? Sep 21, 2013 at 15:41

1 Answer 1

6
\documentclass{article}

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

\def\radius{21.65}
\def\vinkelA{12 }
\pstFPdiv\faktor{1}{3}
\pstFPmul\faktorB{\radius}{\faktor}
\pstFPadd\faktorC{\faktorB}{0.05}
\pstFPadd\faktorD{\faktorB}{2.95}
\makeatletter
  \pst@getsinandcos{\vinkelA}
  \pstFPmul\RelRadius\faktor{\radius}
  \pstFPmul\PSTRadius{1.02}\RelRadius
  \pstFPmul\MaxLW\RelRadius\pst@sin
  \pstFPmul\MaxLW{2}{\MaxLW}
\newcommand\PolyLine[1][\vinkelA]{%
  \psarc(C){!\RelRadius}{!90 #1 add}{180}
  \psline(B)(A)(D)
  \psarc(C){!\RelRadius}{0}{!90 #1 sub}}

\def\light#1{% Sun beams.
\psset{unit=0.7}
 \begin{pspicture}(-\faktorC,-\faktorC)(\faktorC,\faktorD)
   \pst@getsinandcos{#1}
     \ifnum #1 = 90 \let\RelLW\MaxLW
   \else
     \ifnum #1 > 90 \pstFPmul\RelLW{\MaxLW}{\pst@cos}
     \else          \pstFPmul\RelLW{\MaxLW}{\pst@sin}
     \fi
   \fi
   \pnodes(-\RelRadius,-\RelRadius){A}(-\RelRadius,0){B}(0,0){C}%
          (\RelRadius,-\RelRadius){D}(!0 \RelRadius\space \vinkelA cos mul){T1}
   % Filling
   \pscustom[
     linestyle=none,
     fillstyle=gradient,
     gradbegin=blue!5,gradmidpoint=1,gradend=blue!35]{\PolyLine}
   \pscustom[linewidth=2pt,linecolor=red]{\PolyLine[0]}
     \typeout{====\RelRadius}%
   \begin{psclip}{% Clipping.
     \pscustom[linestyle=none,dimen=inner]{%
       {\edef\RelRadius{\RelRadius\space CLW \pst@number\psrunit div sub}%
        \PolyLine}
       \psline[linewidth=2pt](\RelRadius,\RelRadius)(!\RelRadius\space dup 3 add)%
              (!\RelRadius\space dup neg exch 3 add)(-\RelRadius,\RelRadius)
     }
   }
   \rput(!0 \RelRadius\space \vinkelA cos mul){%
     \pcline[linecolor=yellow,linewidth=\RelLW,nodesep=-\radius
     ](0,0)(!#1 dup 90 ne {-1 exch neg Tan neg} {0 -1} ifelse)}
   \end{psclip}
   \psline[linestyle=dotted]({-\RelRadius,0}|T1)({\RelRadius,0}|T1)
   \rput(!\RelRadius\space 90 \vinkelA sub PtoC){%
     \pswedge(0,0){1}{!180 #1 sub}{180}
     \uput{1}[!180 #1 2 div sub](0,0){\footnotesize \SI{#1}{\degree}}
     \psline[linestyle=dotted](0,0)(!3 180 #1 sub PtoC)
   }
 \end{pspicture}
}

\begin{document}

\begin{animateinline}[poster=first,controls,palindrome]{2}
  \multiframe{121}{iA=30+1}{\light{\iA}}
\end{animateinline}

\end{document}

enter image description here

3
  • It looks good. Come to think of it, I would like the red curve to be cut off vertical at both sides of the yellow parallellogram since the drawing illustrates light coming through a hole in a ceiling. Furthermore, the light should go through the hole hitting the top of the left-hand side of the curve and the bottom of the right-hand side of the curve. (I hope it makes sence.) Sep 21, 2013 at 16:11
  • I changed the code. Substract the linewidth from the clip area for the yellow line. A vertical cut of the line is possible if you shorten the line at the end yellow edges.
    – user2478
    Sep 21, 2013 at 16:24
  • I see that you have incorporated the subtraction of the linewidth (nice!) but it is not compeltely perfect; the right-most part of the parallellogram overlaps a tiny bit of the red curve. Also, I can't figure out how to get a vertical cut of the line. Sep 24, 2013 at 5:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .