Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###########################
- # Pitch_Plane_Functions.r #
- ###########################
- # The following contains several functions related to the plane of a pitch using PITCHf/x data and movement.
- ###################
- # Binormal Vector #
- ###################
- # PITCH is a list containing the 9 PITCHf/x parameters
- Binormal_Vector <- function(PITCH){
- # Set the velocity vector
- V <- c(PITCH$vx0,PITCH$vy0,PITCH$vz0);
- # Set the acceleration vector
- A <- c(PITCH$ax,PITCH$ay,PITCH$az);
- # Find and normalize the binormal vector
- V_x_A <- c(V[2]*A[3] - V[3]*A[2],V[3]*A[1] - V[1]*A[3],V[1]*A[2] - V[2]*A[1]);
- V_x_A_norm <- sqrt(V_x_A[1]^2 + V_x_A[2]^2 + V_x_A[3]^2);
- return(V_x_A/V_x_A_norm);
- }
- ##################
- # PITCHf/x Basis #
- ##################
- # PITCH is a list containing the 9 PITCHf/x parameters
- PFX_Basis <- function(PITCH){
- # Set the binormal vector
- V1 <- Binormal_Vector(PITCH);
- # Set the u-vector
- V2 <- sign(V1[1])*c(-V1[2],V1[1],0)/sqrt(V1[1]^2 + V1[2]^2);
- # Set the w-vector
- V3 <- sign(V1[1]*V2[2]-V1[2]*V2[1])*c(-V1[3]*V2[2],V1[3]*V2[1],V1[1]*V2[2]-V1[2]*V2[1]);
- V3 <- V3/sqrt(V3[1]^2 + V3[2]^2 + V3[3]^2);
- # Build a matrix containing the vectors
- V <- array(0,dim=c(3,3));
- V[,1] <- V1;
- V[,2] <- V2;
- V[,3] <- V3;
- return(V);
- }
- ##########################################
- # Angle of Binormal Vector from Vertical #
- ##########################################
- # PITCH is a list containing the 9 PITCHf/x parameters
- Vertical_Angle <- function(PITCH){
- # Find the PITCHf/x basis
- BV <- PFX_Basis(PITCH);
- BV_T <- t(BV);
- # Set the w-vector
- W <- BV_T[3,];
- # Find the angle w makes with vertical (0,0,1)
- rho <- 180*acos(abs(W[3]))/pi;
- # Assign the angle the correct sign
- if (W[1] < 0){rho <- -abs(rho);} else {rho <- abs(rho);}
- return(rho);
- }
- #####################
- # In-Plane Movement #
- #####################
- # PITCH is a list containing the 9 PITCHf/x parameters
- IP_Movement <- function(PITCH){
- # Find the time for the pitch to reach 40 feet in xyz-space
- a <- 0.5*PITCH$ay;
- b <- PITCH$vy0;
- c_40 <- PITCH$y0 - 40;
- t_40 <- (-b - sqrt(b^2 - 4*a*c_40))/(2*a);
- # Find the time for the pitch to reach the plate in xyz-space
- c_plate <- PITCH$y0 - (17/12);
- t_plate <- (-b - sqrt(b^2 - 4*a*c_plate))/(2*a);
- # Find the PITCHf/x basis
- BV <- PFX_Basis(PITCH);
- BV_T <- t(BV);
- # Find the w-acceleration of the pitch and w-component of gravity
- aw <- BV_T[3,] %*% c(PITCH$ax,PITCH$ay,PITCH$az);
- gw <- BV_T[3,] %*% c(0,0,-32.174);
- # Compute the in-plane movement, in inches
- return(6*(aw-gw)*(t_plate - t_40)^2);
- }
- ##################################
- # In-Plane Movement with Gravity #
- ##################################
- # PITCH is a list containing the 9 PITCHf/x parameters
- IP_Movement_G <- function(PITCH){
- # Find the time for the pitch to reach 40 feet in xyz-space
- a <- 0.5*PITCH$ay;
- b <- PITCH$vy0;
- c_40 <- PITCH$y0 - 40;
- t_40 <- (-b - sqrt(b^2 - 4*a*c_40))/(2*a);
- # Find the time for the pitch to reach the plate in xyz-space
- c_plate <- PITCH$y0 - (17/12);
- t_plate <- (-b - sqrt(b^2 - 4*a*c_plate))/(2*a);
- # Find the PITCHf/x basis
- BV <- PFX_Basis(PITCH);
- BV_T <- t(BV);
- # Find the w-acceleration of the pitch
- aw <- BV_T[3,] %*% c(PITCH$ax,PITCH$ay,PITCH$az);
- # Compute the in-plane movement, in inches
- return(6*aw*(t_plate - t_40)^2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement