How to use the pytransform3d.rotations.random_quaternion function in pytransform3d

To help you get started, we’ve selected a few pytransform3d examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rock-learning / pytransform3d / transformation_ambiguities-5.py View on Github external
import numpy as np
import matplotlib.pyplot as plt
from pytransform3d.rotations import random_quaternion, q_id
from pytransform3d.transformations import transform_from_pq
from pytransform3d.transform_manager import TransformManager


random_state = np.random.RandomState(0)

camera2body = transform_from_pq(
    np.hstack((np.array([0.4, -0.3, 0.5]),
               random_quaternion(random_state))))
object2camera = transform_from_pq(
    np.hstack((np.array([0.0, 0.0, 0.3]),
               random_quaternion(random_state))))

tm = TransformManager()
tm.add_transform("camera", "body", camera2body)
tm.add_transform("object", "camera", object2camera)

ax = tm.plot_frames_in("body", s=0.1)
ax.set_xlim((-0.15, 0.65))
ax.set_ylim((-0.4, 0.4))
ax.set_zlim((0.0, 0.8))
plt.show()
github rock-learning / pytransform3d / examples / plot_transform_manager.py View on Github external
"""
print(__doc__)


import numpy as np
import matplotlib.pyplot as plt
from pytransform3d.rotations import (random_quaternion, matrix_from_euler_xyz,
                                     q_id)
from pytransform3d.transformations import transform_from_pq, transform_from
from pytransform3d.transform_manager import TransformManager


random_state = np.random.RandomState(0)

ee2robot = transform_from_pq(
    np.hstack((np.array([0.4, -0.3, 0.5]), random_quaternion(random_state))))
cam2robot = transform_from_pq(
    np.hstack((np.array([0.0, 0.0, 0.8]), q_id)))
object2cam = transform_from(
    matrix_from_euler_xyz(np.array([0.0, 0.0, 0.5])), np.array([0.5, 0.1, 0.1]))

tm = TransformManager()
tm.add_transform("end-effector", "robot", ee2robot)
tm.add_transform("camera", "robot", cam2robot)
tm.add_transform("object", "camera", object2cam)

ee2object = tm.get_transform("end-effector", "object")

ax = tm.plot_frames_in("robot", s=0.1)
ax.set_xlim((-0.25, 0.75))
ax.set_ylim((-0.5, 0.5))
ax.set_zlim((0.0, 1.0))
github rock-learning / pytransform3d / pytransform3d / transformations.py View on Github external
"""Generate an random transform.

    Each component of the translation will be sampled from
    :math:`\mathcal{N}(\mu=0, \sigma=1)`.

    Parameters
    ----------
    random_state : np.random.RandomState, optional (default: random seed 0)
        Random number generator

    Returns
    -------
    A2B : array-like, shape (4, 4)
        Random transform from frame A to frame B
    """
    q = random_quaternion(random_state)
    R = matrix_from_quaternion(q)
    p = random_vector(random_state, n=3)
    return transform_from(R=R, p=p)