Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Mayitzin/ahrs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayitzin committed Mar 15, 2024
2 parents 5d84feb + 761ff0e commit db29715
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ahrs/common/quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2116,14 +2116,17 @@ def __new__(subtype, q: np.ndarray = None, versors: bool = True, order: str = 'H
q = np.array(q, dtype=float)
if q.ndim != 2 or q.shape[-1] not in [3, 4]:
raise ValueError(f"Expected array to have shape (N, 4) or (N, 3), got {q.shape}.")
q_norm = np.linalg.norm(q, axis=1)
if sum(~(q_norm > 0)):
raise ValueError("Quaternion values must be non-zero.")

# Build pure quaternions if given as N-by-3 array
if q.shape[-1] == 3:
q = np.c_[np.zeros(q.shape[0]), q]

# Normalize quaternions if versors is True
if versors:
q /= np.linalg.norm(q, axis=1)[:, None]
q = q / q_norm[:, None]

# Create the ndarray instance of type QuaternionArray. This will call
# the standard ndarray constructor, but return an object of type
Expand Down

0 comments on commit db29715

Please sign in to comment.