ostk.mathematics.geometry.d3.transformation.rotation.Quaternion¶
- class Quaternion(*args, **kwargs)¶
Bases:
pybind11_objectOverloaded function.
__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)
__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)
__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)
__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
Compute the angular difference with another quaternion.
Conjugate the quaternion in-place.
Perform cross multiplication with another quaternion.
Perform dot multiplication with another quaternion.
Compute the dot product with another quaternion.
Create a quaternion from Euler angles.
Compute the exponential of the quaternion.
Get the scalar part of the quaternion.
Get the vector part of the quaternion.
Invert the quaternion in-place.
Check if the quaternion is defined.
Check if the quaternion is near another quaternion.
Check if the quaternion is unitary.
Linear interpolation between two quaternions.
Compute the natural logarithm of the quaternion.
Normalized linear interpolation between two quaternions.
Compute the norm (magnitude) of the quaternion.
Normalize the quaternion in-place.
Parse a quaternion from a string.
Raise the quaternion to a power.
Rectify the quaternion in-place (ensure positive scalar part).
Rotate a vector using this quaternion.
Create a quaternion from a rotation matrix.
Create a quaternion from a rotation vector.
Get the s-coordinate of the quaternion.
Create a quaternion representing the shortest rotation between two vectors.
Spherical linear interpolation between two quaternions.
Get the conjugate of the quaternion.
Get the inverse of the quaternion.
Get a normalized copy of the quaternion.
Overloaded function.
Convert the quaternion to a 4D vector.
Create an undefined quaternion.
Create a unit quaternion (identity rotation).
Get the x-coordinate of the quaternion.
Create a quaternion in XYZS format.
Get the y-coordinate of the quaternion.
Get the z-coordinate of the quaternion.
- __add__(
- self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
- arg0: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
- __mul__(*args, **kwargs)¶
Overloaded function.
__mul__(self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion, arg0: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion) -> ostk.mathematics.geometry.d3.transformation.rotation.Quaternion
__mul__(self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion, arg0: numpy.ndarray[numpy.float64[3, 1]]) -> numpy.ndarray[numpy.float64[3, 1]]
__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,
Compute the angular difference with another quaternion.
- Parameters:
quaternion (Quaternion) -- The quaternion to compare with.
- Returns:
The angular difference.
- Return type:
Example
>>> q1 = Quaternion.unit() >>> q2 = Quaternion(0.1, 0.2, 0.3, 0.9, Quaternion.Format.XYZS) >>> angle = q1.angular_difference_with(q2)
- conjugate( ) 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,
Perform cross multiplication with another quaternion.
- Parameters:
quaternion (Quaternion) -- The quaternion to multiply with.
- Returns:
The result of cross multiplication.
- Return type:
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,
Perform dot multiplication with another quaternion.
- Parameters:
quaternion (Quaternion) -- The quaternion to multiply with.
- Returns:
The result of dot multiplication.
- Return type:
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,
Compute the dot product with another quaternion.
- Parameters:
quaternion (Quaternion) -- The quaternion to compute dot product with.
- Returns:
The dot product result.
- Return type:
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,
Create a quaternion from Euler angles.
- Parameters:
euler_angle (EulerAngle) -- The Euler angles.
- Returns:
The quaternion representing the rotation.
- Return type:
Example
>>> ea = EulerAngle.zyx(Angle.radians(0.1), Angle.radians(0.2), Angle.radians(0.3)) >>> q = Quaternion.euler_angle(ea)
- exp( ) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion¶
Compute the exponential of the quaternion.
- Returns:
The exponential of the quaternion.
- Return type:
Example
>>> q = Quaternion(0.1, 0.2, 0.3, 0.0, Quaternion.Format.XYZS) >>> exp_q = q.exp()
- get_scalar_part( ) ostk.core.type.Real¶
Get the scalar part of the quaternion.
- Returns:
The scalar part.
- Return type:
Example
>>> q = Quaternion(0.0, 0.0, 0.0, 1.0, Quaternion.Format.XYZS) >>> q.get_scalar_part() # 1.0
- get_vector_part( ) numpy.ndarray[numpy.float64[3, 1]]¶
Get the vector part of the quaternion.
- Returns:
The vector part.
- Return type:
Vector3d
- is_defined( ) bool¶
Check if the quaternion is defined.
- Returns:
True if the quaternion is defined, False otherwise.
- Return type:
- is_near(
- self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
- quaternion: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
- angular_tolerance: ostk::mathematics::geometry::Angle,
- quaternion: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
Check if the quaternion is near another quaternion.
- Returns:
True if the quaternion is near another quaternion, False otherwise.
- Return type:
- is_unitary(
- self: ostk.mathematics.geometry.d3.transformation.rotation.Quaternion,
- norm_tolerance: ostk.core.type.Real = Real.epsilon(),
Check if the quaternion is unitary.
- Returns:
True if the quaternion is unitary, False otherwise.
- Return type:
- 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,
- second_quaternion: 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:
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( ) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion¶
Compute the natural logarithm of the quaternion.
- Returns:
The natural logarithm of the quaternion.
- Return type:
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,
- second_quaternion: 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:
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( ) ostk.core.type.Real¶
Compute the norm (magnitude) of the quaternion.
- Returns:
The norm of the quaternion.
- Return type:
Example
>>> q = Quaternion(1.0, 2.0, 3.0, 4.0, Quaternion.Format.XYZS) >>> magnitude = q.norm()
- normalize( ) 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,
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:
Example
>>> q = Quaternion.parse("[0.0, 0.0, 0.0, 1.0]", Quaternion.Format.XYZS)
- pow( ) 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:
Example
>>> q = Quaternion.unit() >>> powered = q.pow(2.0)
- rectify( ) 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(),
- vector: 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,
Create a quaternion from a rotation matrix.
- Parameters:
rotation_matrix (RotationMatrix) -- The rotation matrix.
- Returns:
The quaternion representing the rotation.
- Return type:
Example
>>> rm = RotationMatrix.identity() >>> q = Quaternion.rotation_matrix(rm)
- static rotation_vector(
- rotation_vector: ostk::mathematics::geometry::d3::transformation::rotation::RotationVector,
Create a quaternion from a rotation vector.
- Parameters:
rotation_vector (RotationVector) -- The rotation vector.
- Returns:
The quaternion representing the rotation.
- Return type:
Example
>>> rv = RotationVector([0.1, 0.2, 0.3], Angle.radians(1.0)) >>> q = Quaternion.rotation_vector(rv)
- s( ) ostk.core.type.Real¶
Get the s-coordinate of the quaternion.
- Returns:
The s-coordinate.
- Return type:
- static shortest_rotation(
- first_vector: numpy.ndarray[numpy.float64[3, 1]],
- second_vector: numpy.ndarray[numpy.float64[3, 1]],
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:
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,
- second_quaternion: 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:
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( ) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion¶
Get the conjugate of the quaternion.
- Returns:
The conjugate quaternion.
- Return type:
Example
>>> q = Quaternion(1.0, 2.0, 3.0, 4.0, Quaternion.Format.XYZS) >>> conjugate = q.to_conjugate()
- to_inverse( ) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion¶
Get the inverse of the quaternion.
- Returns:
The inverse quaternion.
- Return type:
Example
>>> q = Quaternion.unit() >>> inverse = q.to_inverse()
- to_normalized( ) ostk.mathematics.geometry.d3.transformation.rotation.Quaternion¶
Get a normalized copy of the quaternion.
- Returns:
The normalized quaternion.
- Return type:
Example
>>> q = Quaternion(1.0, 1.0, 1.0, 1.0, Quaternion.Format.XYZS) >>> normalized = q.to_normalized()
- to_string(*args, **kwargs)¶
Overloaded function.
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()
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,
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:
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:
Example
>>> q = Quaternion.unit() >>> q.is_unitary() # True
- x( ) ostk.core.type.Real¶
Get the x-coordinate of the quaternion.
- Returns:
The x-coordinate.
- Return type:
- 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,
- second_component: ostk.core.type.Real,
Create a quaternion in XYZS format.
- Parameters:
- Returns:
The quaternion in XYZS format.
- Return type:
Example
>>> q = Quaternion.xyzs(0.0, 0.0, 0.0, 1.0)
- y( ) ostk.core.type.Real¶
Get the y-coordinate of the quaternion.
- Returns:
The y-coordinate.
- Return type:
- z( ) ostk.core.type.Real¶
Get the z-coordinate of the quaternion.
- Returns:
The z-coordinate.
- Return type: