MCPcopy Create free account
hub / github.com/ALRhub/X_IL / quat2axisangle_numpy

Function quat2axisangle_numpy

utils/transform_utils.py:151–178  ·  view source on GitHub ↗

Converts quaternions to axis-angle format. Returns unit vector directions scaled by their angles in radians. Args: quats (np.array): (N, 4) array of quaternions (x,y,z,w) Returns: np.array: (N, 3) array of axis-angle exponential coordinates

(quats)

Source from the content-addressed store, hash-verified

149
150
151def quat2axisangle_numpy(quats):
152 """
153 Converts quaternions to axis-angle format.
154 Returns unit vector directions scaled by their angles in radians.
155
156 Args:
157 quats (np.array): (N, 4) array of quaternions (x,y,z,w)
158
159 Returns:
160 np.array: (N, 3) array of axis-angle exponential coordinates
161 """
162 # Clip quaternion w components
163 quats[:, 3] = np.clip(quats[:, 3], -1.0, 1.0)
164
165 # Calculate denominator
166 den = np.sqrt(1.0 - quats[:, 3] ** 2)
167
168 # Handle zero degree rotations
169 zero_rotations = np.isclose(den, 0.0)
170 axis_angles = np.zeros_like(quats[:, :3])
171
172 # Calculate axis-angle for non-zero rotations
173 non_zero_rotations = ~zero_rotations
174 axis_angles[non_zero_rotations] = (quats[non_zero_rotations, :3] *
175 (2.0 * np.arccos(quats[non_zero_rotations, 3])[:, np.newaxis]) /
176 den[non_zero_rotations][:, np.newaxis])
177
178 return axis_angles
179
180
181def quat2axisangle_torch(quats):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected