Advertisement
matthewrmata

Plane Angle and In-Plane Movement Functions

Jul 23rd, 2016
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 3.33 KB | None | 0 0
  1. ###########################
  2. # Pitch_Plane_Functions.r #
  3. ###########################
  4.  
  5. # The following contains several functions related to the plane of a pitch using PITCHf/x data and movement.
  6.  
  7. ###################
  8. # Binormal Vector #
  9. ###################
  10.  
  11. # PITCH is a list containing the 9 PITCHf/x parameters
  12.  
  13. Binormal_Vector <- function(PITCH){
  14.     # Set the velocity vector
  15.     V <- c(PITCH$vx0,PITCH$vy0,PITCH$vz0);
  16.     # Set the acceleration vector
  17.     A <- c(PITCH$ax,PITCH$ay,PITCH$az);
  18.     # Find and normalize the binormal vector
  19.     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]);
  20.     V_x_A_norm <- sqrt(V_x_A[1]^2 + V_x_A[2]^2 + V_x_A[3]^2);
  21.     return(V_x_A/V_x_A_norm);
  22. }
  23.  
  24. ##################
  25. # PITCHf/x Basis #
  26. ##################
  27.  
  28. # PITCH is a list containing the 9 PITCHf/x parameters
  29.  
  30. PFX_Basis <- function(PITCH){
  31.     # Set the binormal vector
  32.     V1 <- Binormal_Vector(PITCH);
  33.     # Set the u-vector
  34.     V2 <- sign(V1[1])*c(-V1[2],V1[1],0)/sqrt(V1[1]^2 + V1[2]^2);
  35.     # Set the w-vector
  36.     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]);
  37.     V3 <- V3/sqrt(V3[1]^2 + V3[2]^2 + V3[3]^2);
  38.     # Build a matrix containing the vectors
  39.     V <- array(0,dim=c(3,3));
  40.     V[,1] <- V1;
  41.     V[,2] <- V2;
  42.     V[,3] <- V3;
  43.     return(V);
  44. }
  45.  
  46. ##########################################
  47. # Angle of Binormal Vector from Vertical #
  48. ##########################################
  49.  
  50. # PITCH is a list containing the 9 PITCHf/x parameters
  51.  
  52. Vertical_Angle <- function(PITCH){
  53.     # Find the PITCHf/x basis
  54.     BV <- PFX_Basis(PITCH);
  55.     BV_T <- t(BV);
  56.     # Set the w-vector
  57.     W <- BV_T[3,];
  58.     # Find the angle w makes with vertical (0,0,1)
  59.     rho <- 180*acos(abs(W[3]))/pi;
  60.     # Assign the angle the correct sign
  61.     if (W[1] < 0){rho <- -abs(rho);} else {rho <- abs(rho);}
  62.     return(rho);
  63. }
  64.  
  65. #####################
  66. # In-Plane Movement #
  67. #####################
  68.  
  69. # PITCH is a list containing the 9 PITCHf/x parameters
  70.  
  71. IP_Movement <- function(PITCH){
  72.     # Find the time for the pitch to reach 40 feet in xyz-space
  73.     a <- 0.5*PITCH$ay;
  74.     b <- PITCH$vy0;
  75.     c_40 <- PITCH$y0 - 40;
  76.     t_40 <- (-b - sqrt(b^2 - 4*a*c_40))/(2*a);
  77.     # Find the time for the pitch to reach the plate in xyz-space
  78.     c_plate <- PITCH$y0 - (17/12);
  79.     t_plate <- (-b - sqrt(b^2 - 4*a*c_plate))/(2*a);
  80.     # Find the PITCHf/x basis
  81.     BV <- PFX_Basis(PITCH);
  82.     BV_T <- t(BV);
  83.     # Find the w-acceleration of the pitch and w-component of gravity
  84.     aw <- BV_T[3,] %*% c(PITCH$ax,PITCH$ay,PITCH$az);
  85.     gw <- BV_T[3,] %*% c(0,0,-32.174);
  86.     # Compute the in-plane movement, in inches
  87.     return(6*(aw-gw)*(t_plate - t_40)^2);
  88. }
  89.  
  90. ##################################
  91. # In-Plane Movement with Gravity #
  92. ##################################
  93.  
  94. # PITCH is a list containing the 9 PITCHf/x parameters
  95.  
  96. IP_Movement_G <- function(PITCH){
  97.     # Find the time for the pitch to reach 40 feet in xyz-space
  98.     a <- 0.5*PITCH$ay;
  99.     b <- PITCH$vy0;
  100.     c_40 <- PITCH$y0 - 40;
  101.     t_40 <- (-b - sqrt(b^2 - 4*a*c_40))/(2*a);
  102.     # Find the time for the pitch to reach the plate in xyz-space
  103.     c_plate <- PITCH$y0 - (17/12);
  104.     t_plate <- (-b - sqrt(b^2 - 4*a*c_plate))/(2*a);
  105.     # Find the PITCHf/x basis
  106.     BV <- PFX_Basis(PITCH);
  107.     BV_T <- t(BV);
  108.     # Find the w-acceleration of the pitch
  109.     aw <- BV_T[3,] %*% c(PITCH$ax,PITCH$ay,PITCH$az);
  110.     # Compute the in-plane movement, in inches
  111.     return(6*aw*(t_plate - t_40)^2);
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement