Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import numpy as np
import matplotlib.pyplot as plt
import pytransform3d.rotations as pyrot
import pytransform3d.transformations as pytr
p = np.array([0.0, 0.0, -0.5])
a = np.array([0.0, 0.0, 1.0, np.pi])
B2A = pytr.transform_from(pyrot.matrix_from_axis_angle(a), p)
p = np.array([0.3, 0.4, 0.5])
a = np.array([0.0, 0.0, 1.0, -np.pi / 2.0])
C2B = pytr.transform_from(pyrot.matrix_from_axis_angle(a), p)
C2A = pytr.concat(C2B, B2A)
p = pytr.transform(C2A, np.ones(4))
ax = pytr.plot_transform(A2B=B2A)
pytr.plot_transform(ax, A2B=C2A)
ax.scatter(p[0], p[1], p[2])
plt.show()
def _path_transform(self, path):
A2B = np.eye(4)
for from_f, to_f in zip(path[:-1], path[1:]):
A2B = concat(A2B, self.get_transform(from_f, to_f))
return A2B
Parameters
----------
joint_name : string
Name of the joint
angle : float
Joint angle in radians
"""
if joint_name not in self._joints:
raise KeyError("Joint '%s' is not known" % joint_name)
from_frame, to_frame, child2parent, axis, limits = self._joints[joint_name]
angle = np.clip(angle, limits[0], limits[1])
joint_rotation = matrix_from_axis_angle(np.hstack((axis, [angle])))
joint2A = transform_from(joint_rotation, np.zeros(3))
self.add_transform(from_frame, to_frame, concat(joint2A, child2parent))
def update_trajectory(step, n_frames, trajectory):
progress = float(step + 1) / float(n_frames)
H = np.zeros((100, 4, 4))
H0 = transform_from(R_id, np.zeros(3))
H_mod = np.eye(4)
for i, t in enumerate(np.linspace(0, progress, len(H))):
H0[:3, 3] = np.array([t, 0, t])
H_mod[:3, :3] = matrix_from_angle(2, 8 * np.pi * t)
H[i] = concat(H0, H_mod)
trajectory.set_data(H)
return trajectory