title: Trouble with rotating data in accordance with a "spline" polynomial?
body: <p>Here is the code that the issue is in:</p>
  <pre><code>angles = -atan(deriv)
  
  angles = angles*(180/pi)
  
  
  
  #shift coordinates onto their polynomials
  
  d[1:mtp,3] = d[1:mtp,3] + poly[,2]
  
  
  
  #rotated storage matrix
  
  rrr = as.data.frame(matrix(data = NA, ncol = 2, nrow = 9000))
  
  
  
  #for each moment, take in old coordinates and export newly rotated
  
  for(i in 1:mtp){
  
  rotm = matrix(data = c(c(cos(angles[i]),sin(angles[i])),
  
  c(-sin(angles[i]),cos(angles[i]))), ncol=2, nrow = 2)
  
  rotate.1 = d[i,2:3] - poly[i,]
  
  rotate.2 = rotm %*% t(rotate.1)
  
  rotate.3 = rotate.2 + poly[i,]
  
  rrr[i,] = rotate.3
  
  }
  
  
  
  #overwrite coordinates with rotations
  
  d[1:mtp,2:3] = rrr
  </code></pre>
  <p>&quot;deriv&quot; is a numeric vector containing the derivative at each point along the polynomial spline &quot;poly&quot; with columns 1:2 the x and y. &quot;angles&quot; therefore contains the calculated angle to rotate by at each point. &quot;d&quot; is the initial data matrix, with columns 2:3 the x and y.</p>
  <p><a href="https://i.stack.imgur.com/iudX8.png" rel="nofollow noreferrer">Data to be translated and rotated</a></p>
  <p><a href="https://i.stack.imgur.com/TmpCI.png" rel="nofollow noreferrer">&quot;Spline&quot; polynomial along which data will be translated and rotated</a></p>
  <p><a href="https://i.stack.imgur.com/SWYke.png" rel="nofollow noreferrer">Angles along polynomial used during rotation (derived from derivative)</a></p>
  <p><a href="https://i.stack.imgur.com/WbZAB.png" rel="nofollow noreferrer">Data + Spline (translated)</a></p>
  <p><a href="https://i.stack.imgur.com/2ytiO.png" rel="nofollow noreferrer">Translated and (incorrectly) rotated data</a></p>