Convert axis-angle rotations (aka exponential maps) to quaternions. Stable formula from "Practical Parameterization of Rotations Using the Exponential Map". Expects a tensor of shape (*, 3), where * denotes any number of dimensions. Returns a tensor of shape (*, 4).
(e)
| 212 | |
| 213 | |
| 214 | def expmap_to_quaternion(e): |
| 215 | """ |
| 216 | Convert axis-angle rotations (aka exponential maps) to quaternions. |
| 217 | Stable formula from "Practical Parameterization of Rotations Using the Exponential Map". |
| 218 | Expects a tensor of shape (*, 3), where * denotes any number of dimensions. |
| 219 | Returns a tensor of shape (*, 4). |
| 220 | """ |
| 221 | assert e.shape[-1] == 3 |
| 222 | |
| 223 | original_shape = list(e.shape) |
| 224 | original_shape[-1] = 4 |
| 225 | e = e.reshape(-1, 3) |
| 226 | |
| 227 | theta = np.linalg.norm(e, axis=1).reshape(-1, 1) |
| 228 | w = np.cos(0.5 * theta).reshape(-1, 1) |
| 229 | xyz = 0.5 * np.sinc(0.5 * theta / np.pi) * e |
| 230 | return np.concatenate((w, xyz), axis=1).reshape(original_shape) |
| 231 | |
| 232 | |
| 233 | def euler_to_quaternion(e, order): |
nothing calls this directly
no outgoing calls
no test coverage detected