Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \documentclass[12pt]{article}
- \usepackage[paperwidth=200pt, paperheight=200pt,margin=12pt]{geometry}
- \usepackage{color,tikz,ifthen,animate,pgf}
- \begin{document}
- % This code will simulate a pitch based on the 9-parameter PITCHf/x model, including the pitch plane and projections for PITCHf/x movement without (red) and with (blue dashed) accounted for.
- % Written by Matthew Mata, January 2017.
- \thispagestyle{empty}
- % Set the counter
- \newcounter{m}
- \setcounter{m}{0}
- % Set the PITCHf/x parameters
- \pgfmathsetmacro{\xo}{3.841}
- \pgfmathsetmacro{\yo}{50.0}
- \pgfmathsetmacro{\zo}{5.573}
- \pgfmathsetmacro{\vxo}{-17.203}
- \pgfmathsetmacro{\vyo}{-144.942}
- \pgfmathsetmacro{\vzo}{-5.017}
- \pgfmathsetmacro{\ax}{37.647}
- \pgfmathsetmacro{\ay}{49.266}
- \pgfmathsetmacro{\az}{-9.706}
- % Set gravity
- \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 at 55 feet
- \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 end velocities
- \pgfmathsetmacro{\vxend}{\vxo + \tplate*\ax}
- \pgfmathsetmacro{\vyend}{\vyo + \tplate*\ay}
- \pgfmathsetmacro{\vzend}{\vzo + \tplate*\az}
- % 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!75!white, bottom color = blue!25!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 = black!85!white] (-3,3.274) to [out=-1, in=180] (-0.541,3.176) -- (-0.541,2.5) -- (-3,2.5) -- cycle;
- \draw[fill = black!85!white] (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 to the front of home plate without drag
- \pgfmathsetmacro{\xproj}{\vx*(\tplate - \tinc) + \xraw};
- \pgfmathsetmacro{\zproj}{0.5*\g*(\tplate - \tinc)*(\tplate - \tinc) + \vz*(\tplate - \tinc) + \zraw};
- % Projection of the pitch to the front of home plate with drag
- \pgfmathsetmacro{\vxbar}{(\vx+\vxend)/2};
- \pgfmathsetmacro{\vybar}{(\vy+\vyend)/2};
- \pgfmathsetmacro{\vzbar}{(\vz+\vzend)/2};
- \pgfmathsetmacro{\vbar}{1.25*sqrt((\vxbar/1.25)*(\vxbar/1.25) + (\vybar/1.25)*(\vybar/1.25) + (\vzbar/1.25)*(\vzbar/1.25))};
- \pgfmathsetmacro{\vcoeff}{-abs(\ax*(\vxbar/\vbar) + \ay*(\vybar/\vbar) + (\az-\g)*(\vzbar/\vbar))};
- \pgfmathsetmacro{\axdrag}{\vcoeff*(\vxbar/\vbar)};
- \pgfmathsetmacro{\aydrag}{\vcoeff*(\vybar/\vbar)};
- \pgfmathsetmacro{\azdrag}{\g + \vcoeff*(\vzbar/\vbar)};
- \pgfmathsetmacro{\xprojdrag}{0.5*\axdrag*(\tplate-\tinc)*(\tplate-\tinc) + \vx*(\tplate-\tinc) + \xraw};
- \pgfmathsetmacro{\zprojdrag}{0.5*\azdrag*(\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(\ydist,\xdist)};
- \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 both projections
- \draw[red!80!white] (\xproj,\zproj) circle [radius=0.125];
- \draw[blue!80!white,dashed] (\xprojdrag,\zprojdrag) circle [radius=0.125];
- % Display the metrics
- \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}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement