作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题
我正在尝试使用 Kabsch algorithm 来找到两组 4 点之间的最佳旋转,但我得到的错误大得无法接受。我想将红点( P )映射到蓝点( Q ),如图 here 。
我试过的
这是我对 Kabsch 算法的实现,给定 mapping_points
( P ) 和 true_points
( Q ) 的 numpy 数组
mapped_centroid = np.average(mapping_points, axis=0)
true_centroid = np.average(true_points, axis=0)
mapping_points -= mapped_centroid
true_points -= true_centroid
h = np.matmul(mapping_points.T, true_points)
u, s, v = np.linalg.svd(h)
d = np.linalg.det(v @ u.T)
e = np.array([[1, 0, 0], [0, 1, 0], [0, 0, d]])
r = v @ e @ u.T
tt = true_centroid - np.matmul(r, mapped_centroid)
map_list = []
for i in mapping_points:
point = np.matmul(r, i) + tt
map_list.append(np.reshape(point, (1, 3)))
mapped_xyz = np.vstack(map_list)
mapped_xyz
和
true_points
会给出上图中显示的非常不准确的结果。关于我做错了什么的任何想法?
Q = [[ 1774.11606309 -4241.11341178 5259.04277742]
[ 6079.70499031 -98.14197972 -3442.0914569 ]
[ 813.07069876 3334.26289147 -6112.55652513]
[ 1856.72080823 2328.86927901 6322.16611888]]
P = [[ 3172.79468418 727.52462347 7122.70450243]
[ 165.28953155 -3552.32467068 -2045.15346584]
[ 5292.45250241 -1748.52037006 -6181.40300009]
[ 1893.07584225 5897.19719625 3130.41287776]]
最佳答案
我终于想通了(为此而踢自己)。 numpy 的 linalg.svd 返回 v 的转置(技术上共轭转置),所以我的 kabsch 实现是不正确的。这解释了为什么根据 anchor 节点选择会得到截然不同的结果。它应该是:
h = mapping_points.T @ true_points
u, s, vt = np.linalg.svd(h)
v = vt.T
d = np.linalg.det(v @ u.T)
e = np.array([[1, 0, 0], [0, 1, 0], [0, 0, d]])
r = v @ e @ u.T
关于python - 使用 Kabsch 算法在 3d 中进行最佳旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60877274/
问题 我正在尝试使用 Kabsch algorithm 来找到两组 4 点之间的最佳旋转,但我得到的错误大得无法接受。我想将红点( P )映射到蓝点( Q ),如图 here 。 我试过的 这是我对
我是一名优秀的程序员,十分优秀!