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.

Consider the following animation:

\documentclass{article}

\usepackage[margin=2cm]{geometry}
\usepackage{pst-eucl}
\usepackage{animate}
\usepackage{siunitx}

% LaTeX 3 syntax
\ExplSyntaxOn
  \cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff

\def\sundial#1{%
% constants
\def\length{16 }
\def\north{#1 }
% helping constants
\def\northB{\calc{90-\north}}
\def\lengthB{\calc{\length*sin(\northB*pi/180)}}
\def\lengthC{\calc{\length*sin(\north* pi/180)}}
\def\coorx{\calc{\lengthB*sin(\northB*pi/180)}}
\def\coory{\calc{\lengthC*cos(\north* pi/180)}}
\def\maxxA{\calc{\length+0.45}}
\def\maxxB{\calc{1/4*\length*(sin(2*\north*pi/180)+cos(2*\north*pi/180)+3)}}
\def\maxx{\calc{max(\maxxA,\maxxB)}}
\def\maxyA{\calc{1/2*\lengthC*(sin(\north*pi/180)+cos(\north*pi/180))}}
\def\maxyB{\calc{\coory+0.6}}
\def\maxy{\calc{max(\maxyA,\maxyB)}}
% settings
\psset{unit=0.8}
\sisetup{round-mode=places,round-precision=1}
% picture
\fbox{%
\begin{pspicture}(-0.6,-0.15)(\maxx,\maxy)
  \pnodes{P}(0,0)(\coorx,\coory)(\length,0)
  \pspolygon(P0)(P1)(P2)
  \pstMarkAngle{P2}{P0}{P1}{\SI{\north}{\degree}}
  \pstRightAngle{P0}{P1}{P2}
  \pstMarkAngle{P1}{P2}{P0}{\SI{\northB}{\degree}}
  \uput[180](P0){$A$}
  \uput[90](P1){$C$}
  \uput[0](P2){$B$}
  \pstMediatorAB[
    PointSymbol=none,
    PointNameA=none,
    PointNameB=none,
    CodeFig=true,
    CodeFigColor=black
  ]{P1}{P2}{M}{MN}
  \psset{offset=-9pt,linestyle=none,nrot=:U}
  \pcline(P0)(P1)
  \ncput*{\SI{\lengthB}{\cm}}
  \pcline(P1)(P2)
  \ncput*{\SI{\lengthC}{\cm}}
  \pcline[offset=9pt](P0)(P2)
  \ncput*{\SI{\length}{\cm}}
\end{pspicture}%
}
}

\begin{document}

\begin{animateinline}[poster=first,controls,palindrome]{5}
  \multiframe{51}{iA=20+1}{\sundial{\iA}}
\end{animateinline}

\end{document}

output

(Note: The \fbox is only there to illustrate the size of the pspicture frame.)

When I run the animation (from Adobe Reader), the width and the height of the frame doesn't change; instead, the figure gets stretched. How do I fix this?

P.S. When I don't have an animation and choose single (different) values of \north, the frame gets ajusted as I would expect.

Update

I ended up using the following but AlexG's method is better (since the calculations are done automatically):

\documentclass{article}

\usepackage[margin=2cm]{geometry}
\usepackage{pst-eucl}
\usepackage{animate}
\usepackage{siunitx}

% LaTeX 3 syntax
\ExplSyntaxOn
  \cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff

% helping constants
\def\northB{\calc{90-\north}}
\def\lengthB{\calc{\length*sin(\northB*pi/180)}}
\def\lengthC{\calc{\length*sin(\north* pi/180)}}
\def\coorx{\calc{\lengthB*sin(\northB*pi/180)}}
\def\coory{\calc{\lengthC*cos(\north* pi/180)}}
\def\maxx{\calc{(3+2^(1/2))/4*\length-0.2}}% <-- global maximum for the width (minus adjustment)
\def\maxy{\calc{(1+2^(1/2))/4*\length}}%     <-- global maximum for the height

% settings
\psset{unit=0.8}
\sisetup{round-mode=places,round-precision=1}

% sundial
\def\sundial#1{%
% constants
\def\length{16}
\def\north{#1}
% picture
\begin{pspicture}(-0.5,-0.15)(\maxx,\maxy)
  \pnodes{P}(0,0)(\coorx,\coory)(\length,0)
  \pspolygon(P0)(P1)(P2)
  \pstMarkAngle{P2}{P0}{P1}{\small\SI{\north}{\degree}}
  \pstRightAngle{P0}{P1}{P2}
  \pstMarkAngle{P1}{P2}{P0}{\small\SI{\northB}{\degree}}
  \uput[180](P0){$A$}
  \uput[90](P1){$C$}
  \uput[0](P2){$B$}
  \pstMediatorAB[
    PointSymbol=none,
    PointNameA=none,
    PointNameB=none,
    CodeFig=true,
    CodeFigColor=black
  ]{P1}{P2}{M}{MN}
  \psset{offset=-9pt,linestyle=none,nrot=:U}
  \pcline(P0)(P1)
  \ncput*{\SI{\lengthB}{\cm}}
  \pcline(P1)(P2)
  \ncput*{\SI{\lengthC}{\cm}}
  \pcline[offset=9pt](P0)(P2)
  \ncput*{\SI{\length}{\cm}}
\end{pspicture}
}

\begin{document}

\begin{animateinline}[poster=first,controls,palindrome]{5}
  \multiframe{61}{iA=15+1}{\sundial{\iA}}
\end{animateinline}

\end{document}
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

All frames of an animation must have the same size. The first frame determines the animation widget dimensions. The following frames are anamorphically scaled to this size. Thus, if pspicture dimensions are dynamical, all frames except the first one may be stretched or shrinked.

\documentclass{article}

\usepackage[margin=2cm]{geometry}
\usepackage{pst-eucl}
\usepackage{animate}
\usepackage{siunitx}

% LaTeX 3 syntax
\ExplSyntaxOn 
  \cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff

% constants
\def\length{16 }
% helper macros
\def\northB{\calc{90-\north}}
\def\lengthB{\calc{\length*sin(\northB*pi/180)}}
\def\lengthC{\calc{\length*sin(\north* pi/180)}}
\def\coorx{\calc{\lengthB*sin(\northB*pi/180)}}
\def\coory{\calc{\lengthC*cos(\north* pi/180)}}

%parameterized pspicture
\def\sundial#1{%
  \def\north{#1 }
  % settings
  \psset{unit=0.8}
  \sisetup{round-mode=places,round-precision=1}
  % picture
  \fbox{\begin{pspicture}(-0.6,-0.15)(\maxx,\maxy)
    \pnodes{P}(0,0)(\coorx,\coory)(\length,0)
    \pspolygon(P0)(P1)(P2) 
    \pstMarkAngle{P2}{P0}{P1}{\SI{\north}{\degree}}
    \pstRightAngle{P0}{P1}{P2}
    \pstMarkAngle{P1}{P2}{P0}{\SI{\northB}{\degree}}
    \uput[180](P0){$A$}
    \uput[90](P1){$C$}
    \uput[0](P2){$B$} 
    \pstMediatorAB[
      PointSymbol=none,
      PointNameA=none,
      PointNameB=none,
      CodeFig=true,
      CodeFigColor=black
    ]{P1}{P2}{M}{MN}
    \psset{offset=-9pt,linestyle=none,nrot=:U}
    \pcline(P0)(P1)
    \ncput*{\SI{\lengthB}{\cm}}
    \pcline(P1)(P2)
    \ncput*{\SI{\lengthC}{\cm}}
    \pcline[offset=9pt](P0)(P2)
    \ncput*{\SI{\length}{\cm}}
  \end{pspicture}}%
}   

%find max pspicture dims
\def\maxx{0}\def\maxy{0}
\multido{\iA=20+1}{51}{
  \def\north{\iA }
  \def\maxxA{\calc{\length+0.45}}
  \def\maxxB{\calc{1/4*\length*(sin(2*\north*pi/180)+cos(2*\north*pi/180)+3)}}
  \xdef\maxx{\calc{max(\maxx,\maxxA,\maxxB)}}
  \def\maxyA{\calc{1/2*\lengthC*(sin(\north*pi/180)+cos(\north*pi/180))}}
  \def\maxyB{\calc{\coory+0.6}}
  \xdef\maxy{\calc{max(\maxy,\maxyA,\maxyB)}}
}

\begin{document}

\begin{animateinline}[poster=first,controls,palindrome]{5}
  \multiframe{51}{iA=20+1}{\sundial{\iA}}
\end{animateinline}

\end{document}
share|improve this answer
    
Smart method! I ended up doing something similar, except that I calculated the maxiumum of \maxx and \maxy manually. (See my updated question.) –  Svend Tveskæg Sep 18 '13 at 14:23
    
Ah, I see. Higher mathematics ;-). As you, I tidied up my code, moving locally and doubly defined macros out of \sundial and \multido. –  AlexG Sep 18 '13 at 14:45
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.