ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

class Quaternion(*args, **kwargs)

Bases: pybind11_object

Overloaded function.

  1. __init__(self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion, first_component: ostk.core.type.Real, second_component: ostk.core.type.Real, third_component: ostk.core.type.Real, fourth_component: ostk.core.type.Real, format: ostk::mathematics::geometry::d3::transformation::rotation::Quaternion::Format) -> None

    Create a quaternion from four components and format.

    Args:

    first_component (float): First component (x or w depending on format). second_component (float): Second component (y or x depending on format). third_component (float): Third component (z or y depending on format). fourth_component (float): Fourth component (w or z depending on format). format (Quaternion.Format): The quaternion format (XYZS or SXYZ).

    Example:
    >>> q = Quaternion(0.0, 0.0, 0.0, 1.0, Quaternion.Format.XYZS)
    >>> q = Quaternion(1.0, 0.0, 0.0, 0.0, Quaternion.Format.SXYZ)
    
  2. __init__(self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion, vector: numpy.ndarray[numpy.float64[4, 1]], format: ostk::mathematics::geometry::d3::transformation::rotation::Quaternion::Format) -> None

    Create a quaternion from a 4D vector and format.

    Args:

    vector (numpy.array): The 4D vector containing quaternion components. format (Quaternion.Format): The quaternion format.

    Example:
    >>> vector = numpy.array([0.0, 0.0, 0.0, 1.0])
    >>> q = Quaternion(vector, Quaternion.Format.XYZS)
    
  3. __init__(self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion, vector_part: numpy.ndarray[numpy.float64[3, 1]], scalar_part: ostk.core.type.Real) -> None

    Create a quaternion from vector and scalar parts.

    Args:

    vector_part (numpy.array): The vector part (x, y, z components). scalar_part (float): The scalar part (s component).

    Example:
    >>> vector_part = numpy.array([0.0, 0.0, 0.0])
    >>> scalar_part = 1.0
    >>> q = Quaternion(vector_part, scalar_part)
    
  4. __init__(self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion, quaternion: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion) -> None

    Create a quaternion by copying another quaternion.

    Args:

    quaternion (Quaternion): The quaternion to copy.

    Example:
    >>> original = Quaternion(0.0, 0.0, 0.0, 1.0, Quaternion.Format.XYZS)
    >>> copy = Quaternion(original)
    

Methods

angular_difference_with

Compute the angular difference with another quaternion.

conjugate

Conjugate the quaternion in-place.

cross_multiply

Perform cross multiplication with another quaternion.

dot_multiply

Perform dot multiplication with another quaternion.

dot_product

Compute the dot product with another quaternion.

euler_angle

Create a quaternion from Euler angles.

exp

Compute the exponential of the quaternion.

get_scalar_part

Get the scalar part of the quaternion.

get_vector_part

Get the vector part of the quaternion.

inverse

Invert the quaternion in-place.

is_defined

Check if the quaternion is defined.

is_near

Check if the quaternion is near another quaternion.

is_unitary

Check if the quaternion is unitary.

lerp

Linear interpolation between two quaternions.

log

Compute the natural logarithm of the quaternion.

nlerp

Normalized linear interpolation between two quaternions.

norm

Compute the norm (magnitude) of the quaternion.

normalize

Normalize the quaternion in-place.

parse

Parse a quaternion from a string.

pow

Raise the quaternion to a power.

rectify

Rectify the quaternion in-place (ensure positive scalar part).

rotate_vector

Rotate a vector using this quaternion.

rotation_matrix

Create a quaternion from a rotation matrix.

rotation_vector

Create a quaternion from a rotation vector.

s

Get the s-coordinate of the quaternion.

shortest_rotation

Create a quaternion representing the shortest rotation between two vectors.

slerp

Spherical linear interpolation between two quaternions.

to_conjugate

Get the conjugate of the quaternion.

to_inverse

Get the inverse of the quaternion.

to_normalized

Get a normalized copy of the quaternion.

to_string

Overloaded function.

to_vector

Convert the quaternion to a 4D vector.

undefined

Create an undefined quaternion.

unit

Create a unit quaternion (identity rotation).

x

Get the x-coordinate of the quaternion.

xyzs

Create a quaternion in XYZS format.

y

Get the y-coordinate of the quaternion.

z

Get the z-coordinate of the quaternion.

class Format(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion.Format,
value: int,
)

Bases: pybind11_object

Members:

XYZS

SXYZ

property name
__add__(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
arg0: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion
__mul__(*args, **kwargs)

Overloaded function.

  1. __mul__(self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion, arg0: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion) -> ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

  2. __mul__(self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion, arg0: numpy.ndarray[numpy.float64[3, 1]]) -> numpy.ndarray[numpy.float64[3, 1]]

  3. __mul__(self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion, arg0: float) -> ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

angular_difference_with(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
quaternion: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk::mathematics::geometry::Angle

Compute the angular difference with another quaternion.

Parameters:

quaternion (Quaternion) -- The quaternion to compare with.

Returns:

The angular difference.

Return type:

Angle

Example

>>> q1 = Quaternion.unit()
>>> q2 = Quaternion(0.1, 0.2, 0.3, 0.9, Quaternion.Format.XYZS)
>>> angle = q1.angular_difference_with(q2)
conjugate(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) None

Conjugate the quaternion in-place.

Example

>>> q = Quaternion(1.0, 2.0, 3.0, 4.0, Quaternion.Format.XYZS)
>>> q.conjugate()
cross_multiply(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
quaternion: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Perform cross multiplication with another quaternion.

Parameters:

quaternion (Quaternion) -- The quaternion to multiply with.

Returns:

The result of cross multiplication.

Return type:

Quaternion

Example

>>> q1 = Quaternion.unit()
>>> q2 = Quaternion(0.1, 0.2, 0.3, 0.9, Quaternion.Format.XYZS)
>>> result = q1.cross_multiply(q2)
dot_multiply(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
quaternion: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Perform dot multiplication with another quaternion.

Parameters:

quaternion (Quaternion) -- The quaternion to multiply with.

Returns:

The result of dot multiplication.

Return type:

Quaternion

Example

>>> q1 = Quaternion.unit()
>>> q2 = Quaternion(0.1, 0.2, 0.3, 0.9, Quaternion.Format.XYZS)
>>> result = q1.dot_multiply(q2)
dot_product(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
quaternion: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.core.type.Real

Compute the dot product with another quaternion.

Parameters:

quaternion (Quaternion) -- The quaternion to compute dot product with.

Returns:

The dot product result.

Return type:

float

Example

>>> q1 = Quaternion.unit()
>>> q2 = Quaternion(0.1, 0.2, 0.3, 0.9, Quaternion.Format.XYZS)
>>> dot = q1.dot_product(q2)
static euler_angle(
euler_angle: ostk::mathematics::geometry::d3::transformation::rotation::EulerAngle,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Create a quaternion from Euler angles.

Parameters:

euler_angle (EulerAngle) -- The Euler angles.

Returns:

The quaternion representing the rotation.

Return type:

Quaternion

Example

>>> ea = EulerAngle.zyx(Angle.radians(0.1), Angle.radians(0.2), Angle.radians(0.3))
>>> q = Quaternion.euler_angle(ea)
exp(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Compute the exponential of the quaternion.

Returns:

The exponential of the quaternion.

Return type:

Quaternion

Example

>>> q = Quaternion(0.1, 0.2, 0.3, 0.0, Quaternion.Format.XYZS)
>>> exp_q = q.exp()
get_scalar_part(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.core.type.Real

Get the scalar part of the quaternion.

Returns:

The scalar part.

Return type:

float

Example

>>> q = Quaternion(0.0, 0.0, 0.0, 1.0, Quaternion.Format.XYZS)
>>> q.get_scalar_part()  # 1.0
get_vector_part(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) numpy.ndarray[numpy.float64[3, 1]]

Get the vector part of the quaternion.

Returns:

The vector part.

Return type:

Vector3d

inverse(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) None

Invert the quaternion in-place.

Example

>>> q = Quaternion.unit()
>>> q.inverse()
is_defined(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) bool

Check if the quaternion is defined.

Returns:

True if the quaternion is defined, False otherwise.

Return type:

bool

is_near(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
quaternion: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
angular_tolerance: ostk::mathematics::geometry::Angle,
) bool

Check if the quaternion is near another quaternion.

Returns:

True if the quaternion is near another quaternion, False otherwise.

Return type:

bool

is_unitary(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
norm_tolerance: ostk.core.type.Real = Real.epsilon(),
) bool

Check if the quaternion is unitary.

Returns:

True if the quaternion is unitary, False otherwise.

Return type:

bool

static lerp(
first_quaternion: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
second_quaternion: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
ratio: ostk.core.type.Real,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Linear interpolation between two quaternions.

Parameters:
  • first_quaternion (Quaternion) -- The first quaternion.

  • second_quaternion (Quaternion) -- The second quaternion.

  • ratio (float) -- The interpolation ratio (0.0 to 1.0).

Returns:

The interpolated quaternion.

Return type:

Quaternion

Example

>>> q1 = Quaternion.unit()
>>> q2 = Quaternion(0.1, 0.2, 0.3, 0.9, Quaternion.Format.XYZS)
>>> q_interp = Quaternion.lerp(q1, q2, 0.5)
log(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Compute the natural logarithm of the quaternion.

Returns:

The natural logarithm of the quaternion.

Return type:

Quaternion

Example

>>> q = Quaternion.unit()
>>> log_q = q.log()
static nlerp(
first_quaternion: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
second_quaternion: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
ratio: ostk.core.type.Real,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Normalized linear interpolation between two quaternions.

Parameters:
  • first_quaternion (Quaternion) -- The first quaternion.

  • second_quaternion (Quaternion) -- The second quaternion.

  • ratio (float) -- The interpolation ratio (0.0 to 1.0).

Returns:

The normalized interpolated quaternion.

Return type:

Quaternion

Example

>>> q1 = Quaternion.unit()
>>> q2 = Quaternion(0.1, 0.2, 0.3, 0.9, Quaternion.Format.XYZS)
>>> q_interp = Quaternion.nlerp(q1, q2, 0.5)
norm(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.core.type.Real

Compute the norm (magnitude) of the quaternion.

Returns:

The norm of the quaternion.

Return type:

float

Example

>>> q = Quaternion(1.0, 2.0, 3.0, 4.0, Quaternion.Format.XYZS)
>>> magnitude = q.norm()
normalize(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) None

Normalize the quaternion in-place.

Example

>>> q = Quaternion(1.0, 1.0, 1.0, 1.0, Quaternion.Format.XYZS)
>>> q.normalize()
static parse(
string: ostk.core.type.String,
format: ostk::mathematics::geometry::d3::transformation::rotation::Quaternion::Format,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Parse a quaternion from a string.

Parameters:
  • string (str) -- The string representation of the quaternion.

  • format (Quaternion.Format) -- The format of the quaternion.

Returns:

The parsed quaternion.

Return type:

Quaternion

Example

>>> q = Quaternion.parse("[0.0, 0.0, 0.0, 1.0]", Quaternion.Format.XYZS)
pow(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
value: ostk.core.type.Real,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Raise the quaternion to a power.

Parameters:

value (float) -- The exponent.

Returns:

The quaternion raised to the power.

Return type:

Quaternion

Example

>>> q = Quaternion.unit()
>>> powered = q.pow(2.0)
rectify(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) None

Rectify the quaternion in-place (ensure positive scalar part).

Example

>>> q = Quaternion(0.0, 0.0, 0.0, -1.0, Quaternion.Format.XYZS)
>>> q.rectify()
rotate_vector(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
vector: numpy.ndarray[numpy.float64[3, 1]],
norm_tolerance: ostk.core.type.Real = Real.epsilon(),
) numpy.ndarray[numpy.float64[3, 1]]

Rotate a vector using this quaternion.

Parameters:
  • vector (numpy.array) -- The 3D vector to rotate.

  • norm_tolerance (float, optional) -- Tolerance for normalization check.

Returns:

The rotated vector.

Return type:

Vector3d

Example

>>> q = Quaternion.unit()
>>> vector = numpy.array([1.0, 0.0, 0.0])
>>> rotated = q.rotate_vector(vector)
static rotation_matrix(
rotation_matrix: ostk::mathematics::geometry::d3::transformation::rotation::RotationMatrix,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Create a quaternion from a rotation matrix.

Parameters:

rotation_matrix (RotationMatrix) -- The rotation matrix.

Returns:

The quaternion representing the rotation.

Return type:

Quaternion

Example

>>> rm = RotationMatrix.identity()
>>> q = Quaternion.rotation_matrix(rm)
static rotation_vector(
rotation_vector: ostk::mathematics::geometry::d3::transformation::rotation::RotationVector,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Create a quaternion from a rotation vector.

Parameters:

rotation_vector (RotationVector) -- The rotation vector.

Returns:

The quaternion representing the rotation.

Return type:

Quaternion

Example

>>> rv = RotationVector([0.1, 0.2, 0.3], Angle.radians(1.0))
>>> q = Quaternion.rotation_vector(rv)
s(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.core.type.Real

Get the s-coordinate of the quaternion.

Returns:

The s-coordinate.

Return type:

float

static shortest_rotation(
first_vector: numpy.ndarray[numpy.float64[3, 1]],
second_vector: numpy.ndarray[numpy.float64[3, 1]],
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Create a quaternion representing the shortest rotation between two vectors.

Parameters:
  • first_vector (numpy.array) -- The first vector.

  • second_vector (numpy.array) -- The second vector.

Returns:

The quaternion representing the shortest rotation.

Return type:

Quaternion

Example

>>> v1 = numpy.array([1.0, 0.0, 0.0])
>>> v2 = numpy.array([0.0, 1.0, 0.0])
>>> q = Quaternion.shortest_rotation(v1, v2)
static slerp(
first_quaternion: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
second_quaternion: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
ratio: ostk.core.type.Real,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Spherical linear interpolation between two quaternions.

Parameters:
  • first_quaternion (Quaternion) -- The first quaternion.

  • second_quaternion (Quaternion) -- The second quaternion.

  • ratio (float) -- The interpolation ratio (0.0 to 1.0).

Returns:

The spherically interpolated quaternion.

Return type:

Quaternion

Example

>>> q1 = Quaternion.unit()
>>> q2 = Quaternion(0.1, 0.2, 0.3, 0.9, Quaternion.Format.XYZS)
>>> q_interp = Quaternion.slerp(q1, q2, 0.5)
to_conjugate(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Get the conjugate of the quaternion.

Returns:

The conjugate quaternion.

Return type:

Quaternion

Example

>>> q = Quaternion(1.0, 2.0, 3.0, 4.0, Quaternion.Format.XYZS)
>>> conjugate = q.to_conjugate()
to_inverse(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Get the inverse of the quaternion.

Returns:

The inverse quaternion.

Return type:

Quaternion

Example

>>> q = Quaternion.unit()
>>> inverse = q.to_inverse()
to_normalized(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Get a normalized copy of the quaternion.

Returns:

The normalized quaternion.

Return type:

Quaternion

Example

>>> q = Quaternion(1.0, 1.0, 1.0, 1.0, Quaternion.Format.XYZS)
>>> normalized = q.to_normalized()
to_string(*args, **kwargs)

Overloaded function.

  1. to_string(self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion) -> ostk.core.type.String

    Convert the quaternion to string representation.

    Returns:

    str: String representation of the quaternion.

    Example:
    >>> q = Quaternion.unit()
    >>> q.to_string()
    
  2. to_string(self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion, format: ostk::mathematics::geometry::d3::transformation::rotation::Quaternion::Format) -> ostk.core.type.String

    Convert the quaternion to string representation with specified format.

    Args:

    format (Quaternion.Format): The format for string representation.

    Returns:

    str: String representation of the quaternion.

    Example:
    >>> q = Quaternion.unit()
    >>> q.to_string(Quaternion.Format.SXYZ)
    
to_vector(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
format: ostk::mathematics::geometry::d3::transformation::rotation::Quaternion::Format,
) numpy.ndarray[numpy.float64[4, 1]]

Convert the quaternion to a 4D vector.

Parameters:

format (Quaternion.Format) -- The format for the vector components.

Returns:

The quaternion as a 4D vector.

Return type:

Vector4d

Example

>>> q = Quaternion.unit()
>>> vector = q.to_vector(Quaternion.Format.XYZS)
static undefined() ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Create an undefined quaternion.

Returns:

An undefined quaternion.

Return type:

Quaternion

Example

>>> q = Quaternion.undefined()
>>> q.is_defined()  # False
static unit() ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Create a unit quaternion (identity rotation).

Returns:

A unit quaternion.

Return type:

Quaternion

Example

>>> q = Quaternion.unit()
>>> q.is_unitary()  # True
x(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.core.type.Real

Get the x-coordinate of the quaternion.

Returns:

The x-coordinate.

Return type:

float

static xyzs(
first_component: ostk.core.type.Real,
second_component: ostk.core.type.Real,
third_component: ostk.core.type.Real,
fourth_component: ostk.core.type.Real,
) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion

Create a quaternion in XYZS format.

Parameters:
  • first_component (float) -- The x component.

  • second_component (float) -- The y component.

  • third_component (float) -- The z component.

  • fourth_component (float) -- The s component.

Returns:

The quaternion in XYZS format.

Return type:

Quaternion

Example

>>> q = Quaternion.xyzs(0.0, 0.0, 0.0, 1.0)
y(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.core.type.Real

Get the y-coordinate of the quaternion.

Returns:

The y-coordinate.

Return type:

float

z(
self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
) ostk.core.type.Real

Get the z-coordinate of the quaternion.

Returns:

The z-coordinate.

Return type:

float