本文整理汇总了Python中scipy.spatial.transform.Rotation.from_rotvec方法的典型用法代码示例。如果您正苦于以下问题:Python Rotation.from_rotvec方法的具体用法?Python Rotation.from_rotvec怎么用?Python Rotation.from_rotvec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.spatial.transform.Rotation
的用法示例。
在下文中一共展示了Rotation.from_rotvec方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_match_vectors_noise
# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_rotvec [as 别名]
def test_match_vectors_noise():
np.random.seed(0)
n_vectors = 100
rot = Rotation.from_euler('xyz', np.random.normal(size=3))
vectors = np.random.normal(size=(n_vectors, 3))
result = rot.apply(vectors)
# The paper adds noise as indepedently distributed angular errors
sigma = np.deg2rad(1)
tolerance = 1.5 * sigma
noise = Rotation.from_rotvec(
np.random.normal(
size=(n_vectors, 3),
scale=sigma
)
)
# Attitude errors must preserve norm. Hence apply individual random
# rotations to each vector.
noisy_result = noise.apply(result)
est, cov = Rotation.match_vectors(noisy_result, vectors)
# Use rotation compositions to find out closeness
error_vector = (rot * est.inv()).as_rotvec()
assert_allclose(error_vector[0], 0, atol=tolerance)
assert_allclose(error_vector[1], 0, atol=tolerance)
assert_allclose(error_vector[2], 0, atol=tolerance)
# Check error bounds using covariance matrix
cov *= sigma
assert_allclose(cov[0, 0], 0, atol=tolerance)
assert_allclose(cov[1, 1], 0, atol=tolerance)
assert_allclose(cov[2, 2], 0, atol=tolerance)
示例2: test_rotvec_calc_pipeline
# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_rotvec [as 别名]
def test_rotvec_calc_pipeline():
# Include small angles
rotvec = np.array([
[0, 0, 0],
[1, -1, 2],
[-3e-4, 3.5e-4, 7.5e-5]
])
assert_allclose(Rotation.from_rotvec(rotvec).as_rotvec(), rotvec)
示例3: test_constant_attitude
# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_rotvec [as 别名]
def test_constant_attitude():
times = np.arange(10)
rotations = Rotation.from_rotvec(np.ones((10, 3)))
spline = RotationSpline(times, rotations)
times_check = np.linspace(-1, 11)
assert_allclose(spline(times_check).as_rotvec(), 1, rtol=1e-15)
assert_allclose(spline(times_check, 1), 0, atol=1e-19)
assert_allclose(spline(times_check, 2), 0, atol=1e-19)
assert_allclose(spline(5.5).as_rotvec(), 1, rtol=1e-15)
assert_allclose(spline(5.5, 1), 0, atol=1e-19)
assert_allclose(spline(5.5, 2), 0, atol=1e-19)
示例4: test_from_generic_rotvec
# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_rotvec [as 别名]
def test_from_generic_rotvec():
rotvec = [
[1, 2, 2],
[1, -1, 0.5],
[0, 0, 0]
]
expected_quat = np.array([
[0.3324983, 0.6649967, 0.6649967, 0.0707372],
[0.4544258, -0.4544258, 0.2272129, 0.7316889],
[0, 0, 0, 1]
])
assert_array_almost_equal(
Rotation.from_rotvec(rotvec).as_quat(),
expected_quat)
示例5: test_from_rotvec_small_angle
# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_rotvec [as 别名]
def test_from_rotvec_small_angle():
rotvec = np.array([
[5e-4 / np.sqrt(3), -5e-4 / np.sqrt(3), 5e-4 / np.sqrt(3)],
[0.2, 0.3, 0.4],
[0, 0, 0]
])
quat = Rotation.from_rotvec(rotvec).as_quat()
# cos(theta/2) ~~ 1 for small theta
assert_allclose(quat[0, 3], 1)
# sin(theta/2) / theta ~~ 0.5 for small theta
assert_allclose(quat[0, :3], rotvec[0] * 0.5)
assert_allclose(quat[1, 3], 0.9639685)
assert_allclose(
quat[1, :3],
np.array([
0.09879603932153465,
0.14819405898230198,
0.19759207864306931
]))
assert_equal(quat[2], np.array([0, 0, 0, 1]))
示例6: test_malformed_2d_from_rotvec
# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_rotvec [as 别名]
def test_malformed_2d_from_rotvec():
with pytest.raises(ValueError, match='Expected `rot_vec` to have shape'):
Rotation.from_rotvec([
[1, 2, 3, 4],
[5, 6, 7, 8]
])
示例7: test_malformed_1d_from_rotvec
# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_rotvec [as 别名]
def test_malformed_1d_from_rotvec():
with pytest.raises(ValueError, match='Expected `rot_vec` to have shape'):
Rotation.from_rotvec([1, 2])
示例8: test_from_2d_single_rotvec
# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_rotvec [as 别名]
def test_from_2d_single_rotvec():
rotvec = [[1, 0, 0]]
expected_quat = np.array([[0.4794255, 0, 0, 0.8775826]])
result = Rotation.from_rotvec(rotvec)
assert_array_almost_equal(result.as_quat(), expected_quat)