Advertisement
matthewrmata

2D Pitch Plot in UW-Space

Jul 23rd, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 5.20 KB | None | 0 0
  1. #######################################################
  2. # Plot of Pitch in UW-Space (With & Without Movement) #
  3. #######################################################
  4.  
  5. #########
  6. # FILES #
  7. #########
  8.  
  9. source("Pitch_Plane_Functions.r");
  10.  
  11. ########
  12. # MAIN #
  13. ########
  14.  
  15. # PITCHf/x Data
  16. PITCH <- list(ax = -8.2, ay = 29.2, az = -41.24, vx0 = -5.65, vy0 = -121.96, vz0 = 2.27, x0 = 2.6, y0 = 50.0, z0 = 5.35);
  17.  
  18. # Find an orthogonal matrix consisting of basis vectors for the plane transformation
  19. BV <- PFX_Basis(PITCH);
  20.  
  21. # Find the two-angle form of the vector in spherical coordinates
  22. rho <- Vertical_Angle(PITCH);
  23.  
  24. # Find the transpose of the orthogonal matrix
  25. BV_T <- t(BV);
  26.  
  27. # Find the time to the plate
  28. a <- 0.5*PITCH$ay;
  29. b <- PITCH$vy0;
  30. c_plate <- PITCH$y0 - (17/12);
  31. t_plate <- (-b - sqrt(b^2 - 4*a*c_plate))/(2*a);
  32.  
  33. # Find the time at 55 feet (assumed release point)
  34. c_55 <- PITCH$y0 - 55;
  35. t_55 <- (-b - sqrt(b^2 - 4*a*c_55))/(2*a);
  36.  
  37. # Find the time at 4o feet (for in-plane movement calculation)
  38. c_40 <- PITCH$y0 - 40;
  39. t_40 <- (-b - sqrt(b^2 - 4*a*c_40))/(2*a);
  40.  
  41. # Set the number of intervals in the trajectory
  42. N <- 100;
  43.  
  44. # Set the time increment
  45. delta_t <- (t_plate-t_55)/N;
  46.  
  47. # Set up arrays to store the new coordinates
  48. u_coord <- array(0,dim=(N+1));
  49. w_coord <- array(0,dim=(N+1));
  50. w_g_coord <- array(0,dim=(N+1));
  51. w_no_mvt_coord <- array(0,dim=(N+1));
  52. w_no_mvt_g_coord <- array(0,dim=(N+1));
  53.  
  54. # Transform the acceleration, velocity, and position
  55. b0 <- BV_T[1,] %*% c(PITCH$x0,PITCH$y0,PITCH$z0);
  56. u0 <- BV_T[2,] %*% c(PITCH$x0,PITCH$y0,PITCH$z0);
  57. w0 <- BV_T[3,] %*% c(PITCH$x0,PITCH$y0,PITCH$z0);
  58. vu0 <- BV_T[2,] %*% c(PITCH$vx0,PITCH$vy0,PITCH$vz0);
  59. vw0 <- BV_T[3,] %*% c(PITCH$vx0,PITCH$vy0,PITCH$vz0);
  60. au <- BV_T[2,] %*% c(PITCH$ax,PITCH$ay,PITCH$az);
  61. aw <- BV_T[3,] %*% c(PITCH$ax,PITCH$ay,PITCH$az);
  62.  
  63. # Gravity
  64. g <- c(0,0,-32.174);
  65. g_basis <- BV_T %*% g;
  66.  
  67. # Find the position of the pitch in (u,w)-space when y = 40 feet
  68. x_40 <- PITCH$x0 + PITCH$vx0*t_40 + 0.5*PITCH$ax*t_40^2;
  69. y_40 <- PITCH$y0 + PITCH$vy0*t_40 + 0.5*PITCH$ay*t_40^2;
  70. z_40 <- PITCH$z0 + PITCH$vz0*t_40 + 0.5*PITCH$az*t_40^2;
  71. u_40 <- BV_T[2,] %*% c(x_40,y_40,z_40);
  72. w_40 <- BV_T[3,] %*% c(x_40,y_40,z_40);
  73.  
  74. # Find the velocity when y = 40 feet
  75. vx_40 <- PITCH$ax*t_40 + PITCH$vx0;
  76. vy_40 <- PITCH$ay*t_40 + PITCH$vy0;
  77. vz_40 <- PITCH$az*t_40 + PITCH$vz0;
  78. vw_40 <- BV_T[3,] %*% c(vx_40,vy_40,vz_40);
  79.  
  80. # Form the pitch trajectory in (u,w)-space
  81. for (i in 0:N){
  82.     t_current <- t_55 + i*delta_t;
  83.     u <- u0 + vu0*t_current + 0.5*au*t_current^2;
  84.     w <- w0 + vw0*t_current + 0.5*aw*t_current^2;
  85.     if (t_current < t_40){
  86.         w_no_mvt <- w;
  87.         w_no_mvt_g <- w;
  88.     } else {
  89.         w_no_mvt <- w_40 + vw_40*(t_current - t_40) + 0.5*g_basis[3]*(t_current-t_40)^2;
  90.         w_no_mvt_g <- w_40 + vw_40*(t_current - t_40);
  91.     }
  92.     u_coord[i+1] <- u;
  93.     w_coord[i+1] <- w;
  94.     w_no_mvt_coord[i+1] <- w_no_mvt;
  95.     w_no_mvt_g_coord[i+1] <- w_no_mvt_g;
  96. }
  97.  
  98. # Set limits for the plot
  99. u_min <- min(u_coord);
  100. u_max <- max(u_coord);
  101. w_min <- min(w_coord);
  102. w_max <- max(w_coord);
  103. w_no_mvt_min <- min(w_no_mvt_coord);
  104. w_no_mvt_max <- max(w_no_mvt_coord);
  105. w_no_mvt_g_min <- min(w_no_mvt_g_coord);
  106. w_no_mvt_g_max <- max(w_no_mvt_g_coord);
  107. w_all_min <- min(w_min,w_no_mvt_min,w_no_mvt_g_min);
  108. w_all_max <- max(w_max,w_no_mvt_max,w_no_mvt_g_max);
  109.  
  110. K <- 0.01;
  111. u_limits <- c(u_min - 0.01*abs(u_max-u_min),u_max + 0.01*abs(u_max-u_min));
  112. w_limits <- c(w_all_min - 0.01*abs(w_all_max-w_all_min),w_all_max + 0.01*abs(w_all_max-w_all_min));
  113.  
  114. # Calculate the movement
  115. mvt <- IP_Movement(PITCH);
  116. mvt_g <- IP_Movement_G(PITCH);
  117.  
  118. # Plot
  119. plot(u_coord,w_no_mvt_coord,pch=20,type='n',xlim=u_limits,ylim=w_limits,xlab="",ylab="",xaxs='i',yaxs='i',xaxt='n',yaxt='n');
  120. lines(u_coord,w_no_mvt_coord,col='green',lwd=2);
  121. par(new=TRUE);
  122. plot(u_coord,w_no_mvt_g_coord,pch=20,type='n',xlim=u_limits,ylim=w_limits,xlab="",ylab="",xaxs='i',yaxs='i',xaxt='n',yaxt='n');
  123. lines(u_coord,w_no_mvt_g_coord,col='blue',lwd=2);
  124. par(new=TRUE);
  125. plot(u_coord,w_coord,pch=20,type='n',xlim=u_limits,ylim=w_limits,xlab="u (feet)",ylab="w (feet)",xaxs='i',yaxs='i',main='Pitch in UW-Space');
  126. lines(u_coord,w_coord,col='red',lwd=2);
  127. par(new=TRUE);
  128. plot(u_40,w_40,pch=20,col='black',xlim=u_limits,ylim=w_limits,xlab="",ylab="",xaxs='i',yaxs='i',xaxt='n',yaxt='n');
  129. par(new=FALSE);
  130. legend(0.99*u_limits[2],1.01*w_limits[1],c('In-Plane Pitch','Minus IPM','Minus IPM & Gravity'),col=c('red','green','blue'),lty=c(1,1,1),lwd=c(2,2,2),xjust=1,yjust=0);
  131.  
  132. # Round all values for display
  133. rho <- round(rho,digits=3);
  134. u0 <- round(u0,digits=3);
  135. w0 <- round(w0,digits=3);
  136. b0 <- round(b0,digits=3);
  137. vu0 <- round(vu0,digits=3);
  138. vw0 <- round(vw0,digits=3);
  139. au <- round(au,digits=3);
  140. aw <- round(aw,digits=3);
  141. g_basis <- round(g_basis,digits=3);
  142. mvt <- round(mvt,digits=3);
  143. mvt_g <- round(mvt_g,digits=3);
  144.  
  145. # Print relevant values
  146. print(paste("angle = ",rho,"",sep=""));
  147. print(paste("u0 = ",u0,", w0 = ",w0,", b0 = ",b0,"",sep=""));
  148. print(paste("vu0 = ",vu0,", vw0 = ",vw0,"",sep=""));
  149. print(paste("au = ",au,", aw = ",aw,"",sep=""));
  150. print(paste("gravity = (",g_basis[1],",",g_basis[2],",",g_basis[3],")",sep=""));
  151. print(paste("movement = ",mvt," inches",sep=""));
  152. print(paste("movement + gravity = ",mvt_g," inches",sep=""));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement