当前位置: 首页>>代码示例>>Python>>正文


Python Rotation.from_dcm方法代码示例

本文整理汇总了Python中scipy.spatial.transform.Rotation.from_dcm方法的典型用法代码示例。如果您正苦于以下问题:Python Rotation.from_dcm方法的具体用法?Python Rotation.from_dcm怎么用?Python Rotation.from_dcm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.spatial.transform.Rotation的用法示例。


在下文中一共展示了Rotation.from_dcm方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_apply_single_rotation_single_point

# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_dcm [as 别名]
def test_apply_single_rotation_single_point():
    dcm = np.array([
        [0, -1, 0],
        [1, 0, 0],
        [0, 0, 1]
    ])
    r_1d = Rotation.from_dcm(dcm)
    r_2d = Rotation.from_dcm(np.expand_dims(dcm, axis=0))

    v_1d = np.array([1, 2, 3])
    v_2d = np.expand_dims(v_1d, axis=0)
    v1d_rotated = np.array([-2, 1, 3])
    v2d_rotated = np.expand_dims(v1d_rotated, axis=0)

    assert_allclose(r_1d.apply(v_1d), v1d_rotated)
    assert_allclose(r_1d.apply(v_2d), v2d_rotated)
    assert_allclose(r_2d.apply(v_1d), v2d_rotated)
    assert_allclose(r_2d.apply(v_2d), v2d_rotated)

    v1d_inverse = np.array([2, -1, 3])
    v2d_inverse = np.expand_dims(v1d_inverse, axis=0)

    assert_allclose(r_1d.apply(v_1d, inverse=True), v1d_inverse)
    assert_allclose(r_1d.apply(v_2d, inverse=True), v2d_inverse)
    assert_allclose(r_2d.apply(v_1d, inverse=True), v2d_inverse)
    assert_allclose(r_2d.apply(v_2d, inverse=True), v2d_inverse)
开发者ID:ElDeveloper,项目名称:scipy,代码行数:28,代码来源:test_rotation.py

示例2: test_from_dcm_calculation

# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_dcm [as 别名]
def test_from_dcm_calculation():
    expected_quat = np.array([1, 1, 6, 1]) / np.sqrt(39)
    dcm = np.array([
            [-0.8974359, -0.2564103, 0.3589744],
            [0.3589744, -0.8974359, 0.2564103],
            [0.2564103, 0.3589744, 0.8974359]
            ])
    assert_array_almost_equal(
            Rotation.from_dcm(dcm).as_quat(),
            expected_quat)
    assert_array_almost_equal(
            Rotation.from_dcm(dcm.reshape((1, 3, 3))).as_quat(),
            expected_quat.reshape((1, 4)))
开发者ID:ElDeveloper,项目名称:scipy,代码行数:15,代码来源:test_rotation.py

示例3: test_apply_multiple_rotations_single_point

# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_dcm [as 别名]
def test_apply_multiple_rotations_single_point():
    dcm = np.empty((2, 3, 3))
    dcm[0] = np.array([
        [0, -1, 0],
        [1, 0, 0],
        [0, 0, 1]
    ])
    dcm[1] = np.array([
        [1, 0, 0],
        [0, 0, -1],
        [0, 1, 0]
    ])
    r = Rotation.from_dcm(dcm)

    v1 = np.array([1, 2, 3])
    v2 = np.expand_dims(v1, axis=0)

    v_rotated = np.array([[-2, 1, 3], [1, -3, 2]])

    assert_allclose(r.apply(v1), v_rotated)
    assert_allclose(r.apply(v2), v_rotated)

    v_inverse = np.array([[2, -1, 3], [1, 3, -2]])

    assert_allclose(r.apply(v1, inverse=True), v_inverse)
    assert_allclose(r.apply(v2, inverse=True), v_inverse)
开发者ID:ElDeveloper,项目名称:scipy,代码行数:28,代码来源:test_rotation.py

示例4: test_apply_single_rotation_multiple_points

# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_dcm [as 别名]
def test_apply_single_rotation_multiple_points():
    dcm = np.array([
        [0, -1, 0],
        [1, 0, 0],
        [0, 0, 1]
    ])
    r1 = Rotation.from_dcm(dcm)
    r2 = Rotation.from_dcm(np.expand_dims(dcm, axis=0))

    v = np.array([[1, 2, 3], [4, 5, 6]])
    v_rotated = np.array([[-2, 1, 3], [-5, 4, 6]])

    assert_allclose(r1.apply(v), v_rotated)
    assert_allclose(r2.apply(v), v_rotated)

    v_inverse = np.array([[2, -1, 3], [5, -4, 6]])

    assert_allclose(r1.apply(v, inverse=True), v_inverse)
    assert_allclose(r2.apply(v, inverse=True), v_inverse)
开发者ID:ElDeveloper,项目名称:scipy,代码行数:21,代码来源:test_rotation.py

示例5: test_from_single_3d_dcm

# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_dcm [as 别名]
def test_from_single_3d_dcm():
    dcm = np.array([
        [0, 0, 1],
        [1, 0, 0],
        [0, 1, 0]
        ]).reshape((1, 3, 3))
    expected_quat = np.array([0.5, 0.5, 0.5, 0.5]).reshape((1, 4))
    assert_array_almost_equal(
            Rotation.from_dcm(dcm).as_quat(),
            expected_quat)
开发者ID:ElDeveloper,项目名称:scipy,代码行数:12,代码来源:test_rotation.py

示例6: test_from_single_2d_dcm

# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_dcm [as 别名]
def test_from_single_2d_dcm():
    dcm = [
            [0, 0, 1],
            [1, 0, 0],
            [0, 1, 0]
            ]
    expected_quat = [0.5, 0.5, 0.5, 0.5]
    assert_array_almost_equal(
            Rotation.from_dcm(dcm).as_quat(),
            expected_quat)
开发者ID:ElDeveloper,项目名称:scipy,代码行数:12,代码来源:test_rotation.py

示例7: test_from_dcm_ortho_output

# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_dcm [as 别名]
def test_from_dcm_ortho_output():
    np.random.seed(0)
    dcm = np.random.random((100, 3, 3))
    ortho_dcm = Rotation.from_dcm(dcm).as_dcm()

    mult_result = np.einsum('...ij,...jk->...ik', ortho_dcm,
                            ortho_dcm.transpose((0, 2, 1)))

    eye3d = np.zeros((100, 3, 3))
    for i in range(3):
        eye3d[:, i, i] = 1.0

    assert_array_almost_equal(mult_result, eye3d)
开发者ID:ElDeveloper,项目名称:scipy,代码行数:15,代码来源:test_rotation.py

示例8: test_getitem

# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_dcm [as 别名]
def test_getitem():
    dcm = np.empty((2, 3, 3))
    dcm[0] = np.array([
        [0, -1, 0],
        [1, 0, 0],
        [0, 0, 1]
    ])
    dcm[1] = np.array([
        [1, 0, 0],
        [0, 0, -1],
        [0, 1, 0]
    ])
    r = Rotation.from_dcm(dcm)

    assert_allclose(r[0].as_dcm(), dcm[0])
    assert_allclose(r[1].as_dcm(), dcm[1])
    assert_allclose(r[:-1].as_dcm(), np.expand_dims(dcm[0], axis=0))
开发者ID:ElDeveloper,项目名称:scipy,代码行数:19,代码来源:test_rotation.py

示例9: test_n_rotations

# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_dcm [as 别名]
def test_n_rotations():
    dcm = np.empty((2, 3, 3))
    dcm[0] = np.array([
        [0, -1, 0],
        [1, 0, 0],
        [0, 0, 1]
    ])
    dcm[1] = np.array([
        [1, 0, 0],
        [0, 0, -1],
        [0, 1, 0]
    ])
    r = Rotation.from_dcm(dcm)

    assert_equal(len(r), 2)
    assert_equal(len(r[0]), 1)
    assert_equal(len(r[1]), 1)
    assert_equal(len(r[:-1]), 1)
开发者ID:ElDeveloper,项目名称:scipy,代码行数:20,代码来源:test_rotation.py

示例10: test_apply_multiple_rotations_multiple_points

# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_dcm [as 别名]
def test_apply_multiple_rotations_multiple_points():
    dcm = np.empty((2, 3, 3))
    dcm[0] = np.array([
        [0, -1, 0],
        [1, 0, 0],
        [0, 0, 1]
    ])
    dcm[1] = np.array([
        [1, 0, 0],
        [0, 0, -1],
        [0, 1, 0]
    ])
    r = Rotation.from_dcm(dcm)

    v = np.array([[1, 2, 3], [4, 5, 6]])
    v_rotated = np.array([[-2, 1, 3], [4, -6, 5]])
    assert_allclose(r.apply(v), v_rotated)

    v_inverse = np.array([[2, -1, 3], [4, 6, -5]])
    assert_allclose(r.apply(v, inverse=True), v_inverse)
开发者ID:ElDeveloper,项目名称:scipy,代码行数:22,代码来源:test_rotation.py

示例11: test_dcm_calculation_pipeline

# 需要导入模块: from scipy.spatial.transform import Rotation [as 别名]
# 或者: from scipy.spatial.transform.Rotation import from_dcm [as 别名]
def test_dcm_calculation_pipeline():
    dcm = special_ortho_group.rvs(3, size=10, random_state=0)
    assert_array_almost_equal(Rotation.from_dcm(dcm).as_dcm(), dcm)
开发者ID:ElDeveloper,项目名称:scipy,代码行数:5,代码来源:test_rotation.py


注:本文中的scipy.spatial.transform.Rotation.from_dcm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。