我对 TEX、PGF 等并不熟悉——但有人好心地为我提供了代码,以便我制作一些我想用的东西。不幸的是,我Dimension too large
在运行以下代码时出错了。我真的很抱歉我的经验不足——如果能得到任何帮助来纠正这个错误,我将不胜感激:
\documentclass[12pt]{article}
\usepackage[paperwidth=200pt, paperheight=200pt,margin=12pt]{geometry}
\usepackage{color,tikz,ifthen,animate}
\begin{document}
% This code will simulate a pitch based on the 9-parameter PITCHf/x model.
% Written by Matthew Mata, November 2014.
\thispagestyle{empty}
% Set the counter
\newcounter{m}
\setcounter{m}{0}
% Set the 9 PITCHf/x parameters
\pgfmathsetmacro{\xo}{-2.463}
\pgfmathsetmacro{\yo}{50}
\pgfmathsetmacro{\zo}{5.419}
\pgfmathsetmacro{\vxo}{11.609}
\pgfmathsetmacro{\vyo}{-144.84}
\pgfmathsetmacro{\vzo}{-7.734}
\pgfmathsetmacro{\ax}{-19.761}
\pgfmathsetmacro{\ay}{34.528}
\pgfmathsetmacro{\az}{-16.898}
\pgfmathsetmacro{\g}{-32.174}
% Set the time to the plate
\pgfmathsetmacro{\r}{\vyo/\ay}
\pgfmathsetmacro{\s}{2*(\yo-(17/12))/\ay}
\pgfmathsetmacro{\tplate}{-\r - sqrt(\r*\r - \s)}
% Set time of release
\pgfmathsetmacro{\u}{2*(\yo-55)/\ay}
\pgfmathsetmacro{\trel}{-\r - sqrt(\r*\r - \u)}
% Set time from release to plate
\pgfmathsetmacro{\t}{\tplate - \trel}
% Set the number of frames
\pgfmathtruncatemacro{\frames}{int(round(\t*60)+1)}
% Set the time increment
\pgfmathsetmacro{\dt}{\t/(\frames-1)}
% Create the animation
\begin{center}
\begin{animateinline}[poster=first,loop,controls]{60}
\whiledo{\them < \frames}{
\begin{tikzpicture}
% Clip off anything out of frame
\clip (-3,0) rectangle (3,5);
% Sky
\shade[top color = blue!50!white, bottom color = blue!10!white] (-3,5) -- (3,5) -- (3,2.5) -- (-3,2.5) -- cycle;
% Grass
\shade[top color = green!50!black, bottom color = green!70!black] (-3,0) -- (3,0) -- (3,2.447) to [out=179, in =0] (0,2.454) to [out=180, in=1] (-3,2.447) -- (-3,0);
% Batter's Eye
\shade[top color = green!60!black, bottom color = green!30!black] (-0.541,3.176) -- (0.541,3.176) -- (0.541,2.5) -- (-0.541,2.5) -- cycle;
% Bleachers
\draw[fill = blue!50!black] (-3,3.274) to [out=-1, in=180] (-0.541,3.176) -- (-0.541,2.5) -- (-3,2.5) -- cycle;
\draw[fill = blue!50!black] (3,3.274) to [out=181, in=0] (0.541,3.176) -- (0.541,2.5) -- (3,2.5) -- cycle;
% Outfield Wall
\shade[top color = green!40!black, bottom color = green!20!black] (-3,2.447) -- (-3,2.659) to [out=-1, in=180] (0,2.639) to [out=0, in=181] (3,2.659) -- (3,2.447) to [out=179, in =0] (0,2.454) to [out=180, in=1] (-3,2.447);
% Yellow Line
\draw[yellow] (-3,2.659) to [out=-1, in=180] (0,2.639) to [out=0, in=181] (3,2.659);
% Mound
\shade[top color = brown!90!black, bottom color = brown!70!black] (-1.014,2.218) to [out=10, in=180] (0,2.312) to [out=0, in=170] (1.014,2.218) to [out=185, in=0] (0,2.174) to [out = 180, in=355] (-1.014,2.218);
% Pitching Rubber
\draw [white] (-0.113,2.312) -- (0.113,2.312);
% Time increment between pitches
\pgfmathsetmacro{\tinc}{\dt*\them + \trel};
% Current flight time of the pitch
\pgfmathsetmacro{\time}{\dt*\them};
% Location of the pitch at the given time
\pgfmathsetmacro{\xraw}{0.5*\ax*\tinc*\tinc + \vxo*\tinc + \xo};
\pgfmathsetmacro{\yraw}{0.5*\ay*\tinc*\tinc + \vyo*\tinc + \yo};
\pgfmathsetmacro{\zraw}{0.5*\az*\tinc*\tinc + \vzo*\tinc + \zo};
% Velocity of the pitch at the given time
\pgfmathsetmacro{\vx}{\ax*\tinc + \vxo};
\pgfmathsetmacro{\vy}{\ay*\tinc + \vyo};
\pgfmathsetmacro{\vz}{\az*\tinc + \vzo};
\pgfmathsetmacro{\vel}{sqrt((15*\vx/22)*(15*\vx/22) + (15*\vy/22)*(15*\vy/22) + (15*\vz/22)*(15*\vz/22))};
% Projection of the pitch into the strike zone
\pgfmathsetmacro{\xproj}{\vx*(\tplate - \tinc) + \xraw};
\pgfmathsetmacro{\zproj}{0.5*\g*(\tplate - \tinc)*(\tplate - \tinc) + \vz*(\tplate - \tinc) + \zraw};
% Distance to the catcher's viewpoint
\pgfmathsetmacro{\xdist}{\xraw};
\pgfmathsetmacro{\ydist}{\yraw + (73/12)};
\pgfmathsetmacro{\zdist}{\zraw - 2.5};
% Spherical coordinates of the pitch
\pgfmathsetmacro{\rad}{sqrt(\xdist*\xdist + \ydist*\ydist + \zdist*\zdist)};
\pgfmathsetmacro{\theta}{atan2(\xdist,\ydist)};
\pgfmathsetmacro{\phi}{acos(\zdist/\rad)};
\pgfmathsetmacro{\radscale}{7.5/(sin(\theta)*sin(\phi))};
% Location of the pitch from the catcher's perspective
\pgfmathsetmacro{\xscale}{\radscale*cos(\theta)*sin(\phi)};
\pgfmathsetmacro{\zscale}{\radscale*cos(\phi) + 2.5};
\pgfmathsetmacro{\rscale}{(7.5*0.125)/\rad};
% Plot the pitch
\draw[shading = ball, ball color = white] (\xscale,\zscale) circle [radius=\rscale];
% Plot the strike zone
\draw[black!85!white] (-17/24,1.5) -- (17/24,1.5) -- (17/24,3.5) -- (-17/24,3.5) -- cycle;
% Plot the projection
\draw[red!80!white] (\xproj,\zproj) circle [radius=0.125];
% Display the diagnostics
\node[above right] at (-3,4.4) {Dist.: };
\node[above left] at (-1,4.4) {\pgfmathprintnumber[precision=1,fixed]{\yraw}};
\node[above right] at (-1.2,4.4) {ft};
\node[above right] at (0,4.4) {Vel.: };
\node[above left] at (2.1,4.4) {\pgfmathprintnumber[precision=1,fixed]{\vel}};
\node[above left] at (3,4.325) {mph};
\node[above right] at (-3,0) {Time: };
\node[above left] at (-0.9,0) {\pgfmathprintnumber[precision=2,fixed]{\time}};
\node[above right] at (-1.1,0) {sec};
\end{tikzpicture}
\stepcounter{m}
\ifthenelse{\them < \frames}{
\newframe
}
{
\end{animateinline} \relax
}
}
\end{center}
\end{document}