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}
- \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}{1.62}
- \pgfmathsetmacro{\yo}{50.0}
- \pgfmathsetmacro{\zo}{6.19}
- \pgfmathsetmacro{\vxo}{-7.97}
- \pgfmathsetmacro{\vyo}{-123.74}
- \pgfmathsetmacro{\vzo}{-8.91}
- \pgfmathsetmacro{\ax}{36.06}
- \pgfmathsetmacro{\ay}{6.56}
- \pgfmathsetmacro{\az}{-19.27}
- % Set gravity
- \pgfmathsetmacro{\g}{-32.174}
- % Find the time to home plate from 50 feet
- \pgfmathsetmacro{\r}{\vyo/\ay}
- \pgfmathsetmacro{\s}{2*(\yo-(17/12))/\ay}
- \pgfmathsetmacro{\tplate}{-\r - sqrt(\r*\r - \s)}
- % Find the time of release at 55 feet
- \pgfmathsetmacro{\u}{2*(\yo-55)/\ay}
- \pgfmathsetmacro{\trel}{-\r - sqrt(\r*\r - \u)}
- % Find the flight time of the pitch to home plate
- \pgfmathsetmacro{\thp}{\tplate - \trel}
- % Set time to catcher's mitt
- \pgfmathsetmacro{\u}{2*(\yo+4)/\ay}
- \pgfmathsetmacro{\tmitt}{-\r - sqrt(\r*\r - \u)}
- % Set time between release and mitt
- \pgfmathsetmacro{\tcm}{\tmitt - \trel}
- % Set the end velocities
- \pgfmathsetmacro{\vxend}{\vxo + \tplate*\ax}
- \pgfmathsetmacro{\vyend}{\vyo + \tplate*\ay}
- \pgfmathsetmacro{\vzend}{\vzo + \tplate*\az}
- % Set the x-location of the pitch at home plate
- \pgfmathsetmacro{\xplate}{0.5*\ax*\tplate*\tplate + \vxo*\tplate + \xo}
- % Set the number of frames
- \pgfmathtruncatemacro{\frames}{int(round(\tcm*60)+1)}
- % Set the number of frames to the plate
- \pgfmathtruncatemacro{\framesplate}{int(round(\thp*60)+1)}
- % Set the time increment
- \pgfmathsetmacro{\dt}{\tcm/(\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 (-2,-2.5) rectangle (4,2.5);
- % Dirt, foul lines, catcher's box, and batter's boxes
- \draw[fill=brown!50!black] (-2,-2.5) -- (4,-2.5) -- (4,2.5) -- (-2,2.5) -- cycle;
- \draw[fill=white!80!brown] (-17/12,-17/24) -- (-17/12,17/24) -- (-8.5/12,17/24) -- (0,0) -- (-8.5/12,-17/24) -- cycle;
- \draw[ultra thick, white!80!brown] (-2,29/24) -- (3,29/24) -- (3,2.5);
- \draw[ultra thick, white!80!brown] (-2,-29/24) -- (3,-29/24) -- (3,-2.5);
- \draw[ultra thick, white!80!brown] (3,43/24) -- (4,43/24);
- \draw[ultra thick, white!80!brown] (3,-43/24) -- (4,-43/24);
- % Time increment between pitches
- \pgfmathsetmacro{\tinc}{\dt*\them + \trel};
- % 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 excluding drag
- \pgfmathsetmacro{\xproj}{\vx*(\tplate - \tinc) + \xraw};
- % Projection of the pitch into the strike zone including 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};
- % Projection of the pitch to the catcher's mitt
- \pgfmathsetmacro{\xmitt}{\vx*(\tmitt - \tinc) + \xraw};
- \ifthenelse{\them < \framesplate}{
- % Plot the projection without drag
- \draw[red] ({(-17/12)},\xproj) circle [radius=0.125];
- % Plot the projection with drag
- \draw[blue,dashed] ({(-17/12)},\xprojdrag) circle [radius=0.125];
- }
- {
- \draw[red] ({(-17/12)},\xplate) circle [radius=0.125];
- \draw[blue,dashed] ({(-17/12)},\xplate) circle [radius=0.125];
- }
- % Plot the ball
- \draw[white, ball color=white, shading=ball] ({-\yraw},\xraw) circle [radius=0.125];
- % Plot the pitch path
- \draw[domain={\trel-0.25}:\tinc,smooth,variable=\x,green] plot ({-0.5*\ay*\x*\x - \vyo*\x - \yo},{0.5*\ax*\x*\x + \vxo*\x + \xo});
- \draw[shading = ball, ball color = white] (-\yraw,\xraw) circle [radius=0.125];
- % Catcher's mitt
- \draw[brown!25!black, fill=brown!25!black] (4,\xmitt) ellipse (0.25 and 0.417);
- % Display the metrics
- \node[above right] at (-2,1.9) {Dist.: };
- \node[below left] at (0.1,2.47) {\pgfmathprintnumber[precision=1,fixed]{\yraw}};
- \node[above right] at (-0.15,1.9) {ft};
- \node[above right] at (-2,-2.5) {Vel.: };
- \node[above left] at (0.1,-2.5) {\pgfmathprintnumber[precision=1,fixed]{\vel}};
- \node[below right] at (-0.1,-1.925) {mph};
- \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