You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

scipy.spatial.transform.Rotation.align_vectors测试脚本返回结果异常

问题:平面对齐中scipy旋转矩阵计算失败的原因排查

我尝试将两个平面对齐中心后,用scipy.spatial.transform.Rotation.align_vectors获取旋转矩阵实现平面对齐,但测试失败。先设计了相对旋转90°的矩形简单案例,运行脚本后提示“给定向量集的最优旋转定义不明确或不佳”,返回单位四元数,结果不符合预期。后续用12个点的复杂案例(点集先沿一个方向旋转90°,再沿另一个方向旋转180°),结果仍无法正确对齐点集,旋转结果存在偏差,求问题原因及排查方向。


简单案例

FROM

0.0 0.0 0.0
1.0 0.0 0.0
0.0 2.0 0.0
1.0 2.0 0.0

TO

0.0 0.0 0.0
2.0 0.0 0.0
2.0 1.0 0.0
0.0 1.0 0.0

测试代码

import numpy as np
import files
from scipy.spatial.transform import Rotation

from_ = np.genfromtxt(files.FROM)
to = np.genfromtxt(files.TO)

mean_from = np.mean(from_, axis=0)
mean_to = np.mean(to, axis=0)

centered_from = from_ - mean_from
centered_to = to - mean_to

rot,res = Rotation.align_vectors(centered_from,centered_to)
print(res)
sol = rot.as_quat()
print("({}f, {}f, {}f, {}f)".format(sol[0],sol[1],sol[2],sol[3]))

运行输出

Optimal rotation is not uniquely or poorly defined for the given sets of vectors.
rot,res = Rotation.align_vectors(centered_from,centered_to)
2.449489742783178
(0.0f, 0.0f, 0.0f, 1.0f)


复杂案例

点集先沿一个方向旋转90°,再沿另一个方向旋转180°

FROM

-1.061441 1.029105 0.3137982
-1.058325 0.6978046 0.3261206
-0.5160019 1.044142 0.5801408
-0.5128856 0.7128415 0.5924632
-0.5150666 1.089168 0.5781018
-0.5124189 0.733911 0.5916736
0.09491175 1.098186 0.6951484
0.09755945 0.7429286 0.7087202
-0.4337781 0.6063982 0.2094956
-0.3675401 0.5803195 0.08044138
-0.1081934 0.6057502 0.3767354
-0.04195532 0.5796715 0.2476811

TO

0.6978049 -1.058325 -0.3261207
0.7128419 -0.5128859 -0.5924634
1.029105 -1.061442 -0.3137983
1.044142 -0.5160022 -0.580141
0.7339112 -0.512419 -0.5916737
0.7429286 0.09755942 -0.7087204
1.089168 -0.5150667 -0.5781019
1.098186 0.09491169 -0.6951486
0.5795034 -0.2047889 -0.1641395
0.5804876 -0.2047065 -0.1639829
0.6055822 -0.271027 -0.2931938
0.6065664 -0.2709446 -0.2930371

内容的提问来源于stack exchange,提问作者Jake_3

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 04:55:59