Utilities (c2g.utils)

capture2go.utils.qmult(q1, q2)[source]

Multiply two quaternions.

Parameters:
  • q1 (np.ndarray) – First quaternion, shape (4,).

  • q2 (np.ndarray) – Second quaternion, shape (4,).

Returns:

The product quaternion, shape (4,).

Return type:

np.ndarray

capture2go.utils.rotate(q, v)[source]

Rotate a 3D vector by a quaternion.

Parameters:
  • q (np.ndarray) – Quaternion, shape (4,).

  • v (np.ndarray) – 3D vector, shape (3,).

Returns:

Rotated 3D vector, shape (3,).

Return type:

np.ndarray

capture2go.utils.rotateinv(q, v)[source]

Rotate a 3D vector by the inverse of a quaternion.

Parameters:
  • q (np.ndarray) – Quaternion, shape (4,).

  • v (np.ndarray) – 3D vector, shape (3,).

Returns:

Rotated 3D vector, shape (3,).

Return type:

np.ndarray

capture2go.utils.quatFromGyr(gyr, rate)[source]

Create an axis-angle quaternion from gyroscope measurements (not integrated).

Parameters:
  • gyr (np.ndarray) – Angular velocity vector(s), shape (…, 3).

  • rate (float) – Sampling rate (Hz).

Returns:

Quaternion(s), shape (…, 4).

Return type:

np.ndarray

capture2go.utils.addHeading(q, delta)[source]

Add a heading (yaw) rotation to a quaternion.

Parameters:
  • q (np.ndarray) – Quaternion, shape (4,).

  • delta (float) – Heading angle in radians.

Returns:

Resulting quaternion, shape (4,).

Return type:

np.ndarray

capture2go.utils.eulerAngles(q, axes='zyx', intrinsic=True)[source]

Convert a quaternion to Euler angles.

Parameters:
  • q (np.ndarray) – Quaternion, shape (4,).

  • axes (str, optional) – Rotation sequence, e.g., ‘zyx’. Defaults to ‘zyx’.

  • intrinsic (bool, optional) – If True, use intrinsic rotations. Defaults to True.

Returns:

Euler angles in radians, order depends on axes and intrinsic.

Return type:

np.ndarray

Raises:

ValueError – If the axes sequence is invalid.

capture2go.utils.decodeQuat(quat)[source]

Decode a compressed 64-bit integer quaternion to a 4-element array.

Parameters:

quat (int) – 64-bit integer encoding a quaternion.

Returns:

  • np.ndarray: Decoded quaternion, shape (4,).

  • bool: outRest flag.

  • bool: outMagDist flag.

Return type:

tuple[np.ndarray, bool, bool]

capture2go.utils.generateSyncId()[source]

Generate a random 64-bit synchronization ID.

When setting the measurement mode, the same ID should be used for all devices that should be synchronized. Whenever the set of sensors changes, generate a new ID.

Returns:

A random 64-bit integer.

Return type:

int