angular_velocity(R, t)
¶
Approximate angular velocity of a rotating frame
Parameters:
Name | Type | Description | Default |
---|---|---|---|
R
|
array_like
|
Quaternion-valued function of time evaluated at a set of times. This represents the quaternion that rotates the standard (x,y,z) frame into the moving frame at each instant. |
required |
t
|
array_like
|
Times at which |
required |
Returns:
Name | Type | Description |
---|---|---|
Omega |
array_like
|
The angular velocity (three-vector) as a function of time |
Notes
The angular velocity at each instant is given by 2 * (dR/dt) / R. This
function approximates the input R
using a cubic spline, and differentiates it
as such.
Source code in quaternion/quaternion_time_series.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
|
integrate_angular_velocity(Omega, t0, t1, R0=None, tolerance=1e-12)
¶
Compute frame with given angular velocity
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Omega
|
tuple or callable
|
Angular velocity from which to compute frame. Can be 1) a 2-tuple of float arrays (t, v) giving the angular velocity vector at a series of times, 2) a function of time that returns the 3-vector angular velocity, or 3) a function of time and orientation (t, R) that returns the 3-vector angular velocity In case 1, the angular velocity will be interpolated to the required times. Note that accuracy is poor in case 1. |
required |
t0
|
float
|
Initial time |
required |
t1
|
float
|
Final time |
required |
R0
|
quaternion
|
Initial frame orientation. Defaults to 1 (the identity orientation). |
None
|
tolerance
|
float
|
Absolute tolerance used in integration. Defaults to 1e-12. |
1e-12
|
Returns:
Name | Type | Description |
---|---|---|
t |
float array
|
|
R |
quaternion array
|
|
Source code in quaternion/quaternion_time_series.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
|
minimal_rotation(R, t, iterations=2)
¶
Adjust frame so that there is no rotation about z' axis
The output of this function is a frame that rotates the z axis onto the same z' axis as the input frame, but with minimal rotation about that axis. This is done by pre-composing the input rotation with a rotation about the z axis through an angle gamma, where
dgamma/dt = 2*(dR/dt * z * R.conjugate()).w
This ensures that the angular velocity has no component along the z' axis.
Note that this condition becomes easier to impose the closer the input rotation is to a minimally rotating frame, which means that repeated application of this function improves its accuracy. By default, this function is iterated twice, though a few more iterations may be called for.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
R
|
quaternion array
|
Time series describing rotation |
required |
t
|
float array
|
Corresponding times at which R is measured |
required |
iterations
|
int [defaults to 2]
|
Repeat the minimization to refine the result |
2
|
Source code in quaternion/quaternion_time_series.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
slerp(R1, R2, t1, t2, t_out)
¶
Spherical linear interpolation of rotors
This function uses a simpler interface than the more fundamental
slerp_evaluate
and slerp_vectorized
functions. The latter
are fast, being implemented at the C level, but take input tau
instead of time. This function adjusts the time accordingly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
R1
|
quaternion
|
Quaternion at beginning of interpolation |
required |
R2
|
quaternion
|
Quaternion at end of interpolation |
required |
t1
|
float
|
Time corresponding to R1 |
required |
t2
|
float
|
Time corresponding to R2 |
required |
t_out
|
float or array of floats
|
Times to which the rotors should be interpolated |
required |
Source code in quaternion/quaternion_time_series.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
squad(R_in, t_in, t_out, unflip_input_rotors=False)
¶
Spherical "quadrangular" interpolation of rotors with a cubic spline
This is typically the best way to interpolate rotation timeseries. It uses the analog of a cubic spline, except that the interpolant is confined to the rotor manifold in a natural way. Alternative methods involving interpolation of other coordinates on the rotation group or normalization of interpolated values give bad results. The results from this method are continuous in value and first derivative everywhere, including around the sampling locations.
The input R_in
rotors are assumed to be reasonably continuous (no
sign flips), and the input t
arrays are assumed to be sorted. No
checking is done for either case, and you may get silently bad
results if these conditions are violated. The first dimension of
R_in
must have the same size as t_in
, but may have additional
axes following.
This function simplifies the calling, compared to squad_evaluate
(which takes a set of four quaternions forming the edges of the
"quadrangle", and the normalized time tau
) and squad_vectorized
(which takes the same arguments, but in array form, and efficiently
loops over them).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
R_in
|
array of quaternions
|
A time-series of rotors (unit quaternions) to be interpolated |
required |
t_in
|
array of float
|
The times corresponding to R_in |
required |
t_out
|
array of float
|
The times to which R_in should be interpolated |
required |
unflip_input_rotors
|
bool
|
If True, this function calls |
False
|
Source code in quaternion/quaternion_time_series.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
unflip_rotors(q, axis=-1, inplace=False)
¶
Flip signs of quaternions along axis to ensure continuity
Quaternions form a "double cover" of the rotation group, meaning that if q
represents a rotation, then -q
represents the same rotation. This is clear
from the way a quaternion is used to rotate a vector v
: the rotated vector is
q * v * q.conjugate()
, which is precisely the same as the vector resulting
from (-q) * v * (-q).conjugate()
. Some ways of constructing quaternions
(such as converting from rotation matrices or other representations) can result
in unexpected sign choices. For many applications, this will not be a problem.
But if, for example, the quaternions need to be interpolated or differentiated,
the results may be surprising. This function flips the signs of successive
quaternions (along some chosen axis, if relevant), so that successive
quaternions are as close as possible while still representing the same
rotations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
q
|
array_like
|
Quaternion array to modify |
required |
axis
|
int
|
Axis along which successive quaternions will be compared. Default value is the last axis of the quaternion array. |
-1
|
inplace
|
bool
|
If True, modify the data in place without creating a copy; if False (the default), a new array is created and returned. |
False
|
Returns:
Name | Type | Description |
---|---|---|
q_out |
array_like
|
An array of precisely the same shape as the input array, differing only by factors of precisely -1 in some elements. |
Source code in quaternion/quaternion_time_series.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|