Skip to content

Commit

Permalink
Use quaternion.quaternion consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond LeClair committed Jan 17, 2023
1 parent 1df035b commit 13e087d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions axis-ptz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import *

import numpy as np
import quaternion

logger = logging.getLogger("utils")
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -485,10 +486,10 @@ def as_quaternion(s, v):
Returns
-------
numpy.ndarray
quaternion.quaternion
A quaternion with the specified scalar and vector parts
"""
return np.append(s, v)
return np.quaternion(s, v[0], v[1], v[2])


def as_rotation_quaternion(d_omega, u):
Expand All @@ -504,27 +505,29 @@ def as_rotation_quaternion(d_omega, u):
Returns
-------
numpy.ndarray
quaternion.quaternion
A rotation quaternion with the specified angle and direction
"""
r_omega = math.radians(d_omega)
return np.append(math.cos(r_omega / 2.0), math.sin(r_omega / 2.0) * u)
v = math.sin(r_omega / 2.0) * u
return np.quaternion(math.cos(r_omega / 2.0), v[0], v[1], v[2])


def as_vector(q):
"""Return the vector part of a .
"""Return the vector part of a quaternion.
Parameters
----------
q : numpy.ndarray
q : quaternion.quaternion
A quaternion, assumed to be a vector quaternion with scalar part zero
Returns
-------
numpy.ndarray
A vector of floats
"""
return q[1:]
return np.array([q.x, q.y, q.z])


def cross(u, v):
"""Compute the cross product of two vectors.
Expand Down

0 comments on commit 13e087d

Please sign in to comment.