如何解决根据“样条”多项式旋转数据有问题吗?
这是问题所在的代码:
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。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。