コード例 #1
0
def test_invert_transform():
    """Test inversion of transformations."""
    random_state = np.random.RandomState(0)
    for _ in range(5):
        R = matrix_from(a=random_axis_angle(random_state))
        p = random_vector(random_state)
        A2B = transform_from(R, p)
        B2A = invert_transform(A2B)
        A2B2 = np.linalg.inv(B2A)
        assert_array_almost_equal(A2B, A2B2)
コード例 #2
0
def test_vector_to_direction():
    """Test conversion from vector to direction in homogenous coordinates."""
    v = np.array([1, 2, 3])
    dA = vector_to_direction(v)
    assert_array_almost_equal(dA, [1, 2, 3, 0])

    random_state = np.random.RandomState(0)
    R = matrix_from(a=random_axis_angle(random_state))
    p = random_vector(random_state)
    A2B = transform_from(R, p)
    assert_transform(A2B)
    _ = transform(A2B, dA)
コード例 #3
0
def test_vector_to_point():
    """Test conversion from vector to homogenous coordinates."""
    v = np.array([1, 2, 3])
    pA = vector_to_point(v)
    assert_array_almost_equal(pA, [1, 2, 3, 1])

    random_state = np.random.RandomState(0)
    R = matrix_from(a=random_axis_angle(random_state))
    p = random_vector(random_state)
    A2B = transform_from(R, p)
    assert_transform(A2B)
    pB = transform(A2B, pA)
コード例 #4
0
ファイル: plot_cylinder.py プロジェクト: vn-os/pytransform3d
==========================
Plot Transformed Cylinders
==========================

Plots surfaces of transformed cylindrical shells.
"""
print(__doc__)

import numpy as np
import matplotlib.pyplot as plt
from pytransform3d.transformations import transform_from, plot_transform
from pytransform3d.rotations import random_axis_angle, matrix_from_axis_angle
from pytransform3d.plot_utils import plot_cylinder, remove_frame

random_state = np.random.RandomState(42)
A2B = transform_from(R=matrix_from_axis_angle(random_axis_angle(random_state)),
                     p=random_state.randn(3))
ax = plot_cylinder(length=1.0,
                   radius=0.3,
                   thickness=0.1,
                   wireframe=False,
                   alpha=0.2)
plot_transform(ax=ax, A2B=np.eye(4), s=0.3, lw=3)
plot_cylinder(ax=ax,
              length=1.0,
              radius=0.3,
              thickness=0.1,
              A2B=A2B,
              wireframe=False,
              alpha=0.2)
plot_transform(ax=ax, A2B=A2B, s=0.3, lw=3)
コード例 #5
0
ファイル: vis_box.py プロジェクト: vn-os/pytransform3d
"""
========
Plot Box
========
"""
print(__doc__)


import numpy as np
import pytransform3d.visualizer as pv
from pytransform3d.transformations import transform_from
from pytransform3d.rotations import random_axis_angle, matrix_from_axis_angle


random_state = np.random.RandomState(42)
fig = pv.figure()
A2B = transform_from(
    R=matrix_from_axis_angle(random_axis_angle(random_state)),
    p=np.zeros(3))
fig.plot_box(size=[0.2, 0.5, 1], A2B=A2B)
fig.plot_transform(A2B=A2B)
fig.view_init()
if "__file__" in globals():
    fig.show()
else:
    fig.save_image("__open3d_rendered_image.jpg")
コード例 #6
0
"""
=====================================
Axis-Angle Representation of Rotation
=====================================

Any rotation can be represented with a single rotation about some axis.
Here we see a frame that is rotated in multiple steps around a rotation
axis.
"""
print(__doc__)

import numpy as np
import matplotlib.pyplot as plt
from pytransform3d.rotations import (random_axis_angle, matrix_from_axis_angle,
                                     plot_basis, plot_axis_angle)

original = random_axis_angle(np.random.RandomState(5))
ax = plot_axis_angle(a=original)
for fraction in np.linspace(0, 1, 50):
    a = original.copy()
    a[-1] = fraction * original[-1]
    R = matrix_from_axis_angle(a)
    plot_basis(ax, R, alpha=0.2)
plt.subplots_adjust(left=0, right=1, bottom=0, top=1.1)
ax.view_init(azim=105, elev=12)
plt.show()