问题描述
这是问题所在的代码:
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
"deriv" 是一个数值向量,包含沿多项式样条 "poly" 的每个点的导数,列 1:2 x 和 y。因此,“angles”包含计算出的每个点旋转的角度。 “d”是初始数据矩阵,列 2:3 是 x 和 y。
Data to be translated and rotated
"Spline" polynomial along which data will be translated and rotated
Angles along polynomial used during rotation (derived from derivative)
Translated and (incorrectly) rotated data
解决方法
已解决:R 三角函数使用弧度,因此脚本不必要地转换为度数并导致过度校正,比例为 180/pi。