Graphics, Figures & TablesPSTricks | Unwanted scaling inside Figure with Animation

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | Unwanted scaling inside Figure with Animation

Post by svend_tveskaeg »

Hi all.

First: This is not a good headline at all, I know, but nothing clever in this regard comes to me at the moment; sorry!

Now, consider the following MWE:

Code: Select all

\documentclass{article}

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

\def\radius{21.65}
\def\faktor{0.3333}
\def\vinkelA{12 }

\newcommand*{\light}[1]{%
 \pstFPmul\RelRadius\faktor{\radius}
 \psset{unit=0.5cm,linecolor=red}
  \begin{pspicture}(43,43)
   \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=2pt,dimen=inner]{%
     \psline(A)(D)\psarc(E){\RelRadius}{0}{180}\psline(B)(A)
     \closepath
   }
   \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 #1 sub](P1)(P2){1}{L1}
   \psRelLine[angle=!360 #1 sub,linestyle=dotted](P2)(P1){1}{L2}
   \psRelLine[angle=!180 #1 sub](P2)(P1){1 \vinkelA cos add 2 \vinkelA sin mul #1 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)
   \rput(!\RelRadius\space 90 \vinkelA\space sub PtoC){%
    \pswedge[linestyle=solid,linewidth=0.5\pslinewidth](P2){0.95}{!180 #1 sub}{180}
    \uput{1}[!180 #1 2 div sub](P2){\footnotesize{\SI{#1}{\degree}}}
   }
  \end{pspicture}
}

\begin{document}

\begin{center}
 \begin{animateinline}[poster=first,controls,palindrome]{10}%
  \multiframe{121}{iAngle=35+1}{\light{\iAngle}}%
 \end{animateinline}%
\end{center}

\end{document}
I have made some (probably trivial) mistake: Doing the different frames in the animation, the height of the drawn building varies.

How do I keep the height constant?

Thank you in advance!

P.S. I compile using

Code: Select all

pdflatex -shell-escape <filename>.tex
if it is of any relevans (but it probably is not...)
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

PSTricks | Unwanted scaling inside Figure with Animation

Post by CrazyHorse »

svend_tveskaeg wrote:How do I keep the height constant?
The example is on the main page http://tug.org/PSTricks/main.cgi
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | Unwanted scaling inside Figure with Animation

Post by svend_tveskaeg »

Nice! :D

I stille have some problems. Here is my code as of now:

Code: Select all

\documentclass{article}

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

\def\radius{21.65}  % Kuplens radius.
\def\faktor{0.3333} % Skaleringsfaktor.
\def\vinkelA{12}    % Vinkel, der bestemmer radius på Oculus.
\makeatletter
 \pst@getsinandcos{\vinkelA}
 \pstFPmul\RelRadius\faktor{\radius}
 \pstFPmul\MaxLW\RelRadius\pst@sin
 \pstFPmul\MaxLW{2}{\MaxLW}
 \def\PolyLine{%
  \psarc(C){\RelRadius}{!90 \vinkelA\space add}{180}
  \psline(B)(A)(D)
  \psarc(C){\RelRadius}{0}{!90 \vinkelA\space sub}
 }

\newcommand*{\light}[1]{%
 \psset{unit=0.5cm}
 \begin{pspicture}(-\RelRadius,-\RelRadius)(\RelRadius,10)
  \pst@getsinandcos{#1}
  \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}
  % Udfyldning af Pantheon.
  \pscustom[linewidth=2pt,linecolor=red,fillstyle=solid,fillcolor=blue!20]{\PolyLine}
  \begin{psclip}{% Afklipningen.
    \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\space cos mul){%
       \pcline[linecolor=yellow,linewidth=\RelLW,nodesep=-\radius]%
              (0,0)(!-1 #1 neg Tan neg)
  }
  \end{psclip}
  \pscustom[linewidth=2pt,linecolor=red]{\PolyLine} % Bedre afklipning.
  \psline[linestyle=dotted]({-\RelRadius,0}|T1)({\RelRadius,0}|T1)
  \rput(!\RelRadius\space 90 \vinkelA\space 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{center}
 \begin{animateinline}[poster=first,controls,palindrome]{10}%
  \multiframe{111}{iAngle=35+1}{\light{\iAngle}}%
 \end{animateinline}%
\end{center}

\end{document}
Issues:
- I would like the width of the rays to be as in my initial post and not get thinner and thinner the closer they get to 90 degrees.
- When the largest values of the angle are reached, some of the rays come in through the roof (not the Oculus). [See the attached picture.]

Wishes:
- Is it possible to get a shadow as in percusse's example on http://tex.stackexchange.com/questions/ ... elogram-if (only darkest at the bottom instead of at the top)?
Attachments
Rays through the roof.
Rays through the roof.
rays.png (12.9 KiB) Viewed 4962 times
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

PSTricks | Unwanted scaling inside Figure with Animation

Post by CrazyHorse »

svend_tveskaeg wrote:Wishes:
- Is it possible to get a shadow as in percusse's example on http://tex.stackexchange.com/questions/ ... elogram-if (only darkest at the bottom instead of at the top)?
For animations it makes no real sense to use pdflatex, the sequence latex->dvips->ps2pdf together with document class standalone is recommended:

Code: Select all

\documentclass[pstricks]{standalone}
%\documentclass{article}
\usepackage{pst-grad,pstricks-add}
\usepackage[locale=DE]{siunitx}
\pagestyle{empty}
\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}
\def\PolyLine{%
  \psarc(C){\RelRadius}{!90 \vinkelA\space add}{180}
  \psline(B)(A)(D)
  \psarc(C){\RelRadius}{0}{!90 \vinkelA\space sub}}
%
\multido{\iA=10+5}{32}{% % Angle of the Sun's rays
\psset{unit=0.5cm}
\begin{pspicture}(-\RelRadius,-\RelRadius)(\RelRadius,10)
  \pst@getsinandcos{\iA}
  \ifnum\iA=90 \let\RelLW\MaxLW
  \else
    \ifnum\iA > 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\space cos mul){T1}
  % the next one for the filling
  \pscustom[linewidth=2pt,linecolor=red,fillstyle=gradient,
    gradbegin=blue!30,gradend=white,gradmidpoint=1]{\PolyLine}
  \begin{psclip}{% now for 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\space cos mul){%
        \pcline[linecolor=yellow,linewidth=\RelLW,nodesep=-\radius]%
       (0,0)(!\iA\space 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\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}
Attachments
Namenlos-4.gif
Namenlos-4.gif (283.75 KiB) Viewed 4961 times
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: PSTricks | Unwanted scaling inside Figure with Animation

Post by svend_tveskaeg »

@Herbert: It works like a charm.

Thank you for helping me (yet again)!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | Unwanted scaling inside Figure with Animation

Post by svend_tveskaeg »

@Herbert: Maybe your example should have the darkest shading at the bottom instead of at the top, i.e., change

Code: Select all

\pscustom[linewidth=2pt,linecolor=red,fillstyle=gradient,
  gradbegin=blue!30,gradend=white,gradmidpoint=1]{\PolyLine}
to

Code: Select all

\pscustom[linewidth=2pt,linecolor=red,fillstyle=gradient,
  gradbegin=white,gradend=blue!30,gradmidpoint=1]{\PolyLine}
(which makes a bit more sense to me) or even

Code: Select all

\pscustom[linewidth=2pt,linecolor=red,fillstyle=gradient,
  gradbegin=blue!5,gradend=blue!35,gradmidpoint=1]{\PolyLine}
Cheers.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply