Class DecimalQuaternion

All Implemented Interfaces:
DecimalVector<Decimal4,Vector4>, BigVector<BigDecimal,BigDecimal,Decimal4,Decimal4,Vector4>, BaseTuple<BigDecimal>, Tuple<BigDecimal>, Serializable, Iterable<BigDecimal>

public class DecimalQuaternion extends Decimal4
An immutable decimal quaternion.
See Also:
  • Field Details

    • IDENTITY

      public static final DecimalQuaternion IDENTITY
      The identity quaternion. This will produce no rotation.
  • Constructor Details

    • DecimalQuaternion

      public DecimalQuaternion(@Nonnull BigDecimal a, @Nonnull BigDecimal b, @Nonnull BigDecimal c, @Nonnull BigDecimal d)
      Creates a new decimal quaternion.
      Parameters:
      a - The A component (the scalar part) of this quaternion
      b - The B component (the vector's A component) of this quaternion
      c - The C component (the vector's B component) of this quaternion
      d - The D component (the vector's C component) of this quaternion
    • DecimalQuaternion

      public DecimalQuaternion(@Nonnull BigDecimal s, @Nonnull Decimal3 v)
      Creates a new decimal quaternion.
      Parameters:
      s - The scalar part of this quaternion.
      v - The vector part of this quaternion
    • DecimalQuaternion

      public DecimalQuaternion(@Nonnull BigDecimal[] components)
      Creates a new decimal quaternion.
      Parameters:
      components - An array containing the components of this quaternion in ABCD order
      Throws:
      IllegalArgumentException - When the provided array's length is not 4
    • DecimalQuaternion

      public DecimalQuaternion(@Nonnull Tuple<? extends BigDecimal> t)
      Creates a new decimal quaternion.
      Parameters:
      t - The tuple of which to copy component values from
      Throws:
      IllegalArgumentException - When the provided tuple t's size is not 4
    • DecimalQuaternion

      public DecimalQuaternion(@Nonnull Vector4 v)
      Creates a new decimal quaternion.
      Parameters:
      v - The vector of which to copy component values from
    • DecimalQuaternion

      public DecimalQuaternion(@Nonnull Quaternion q)
      Creates a new decimal quaternion.
      Parameters:
      q - The quaternion of which to copy component values from
  • Method Details

    • scalar

      @Nonnull public BigDecimal scalar()
      Returns the scalar part of this quaternion.
      Returns:
      The scalar part of this quaternion
    • vector

      @Nonnull public Decimal3 vector()
      Returns the vector part of this quaternion.
      Returns:
      The vector part of this quaternion
    • add

      @Nonnull public DecimalQuaternion add(@Nonnull BigDecimal s)
      Adds a scalar to this quaternion, then returns the resulting quaternion.
      Specified by:
      add in interface BigVector<BigDecimal,BigDecimal,Decimal4,Decimal4,Vector4>
      Overrides:
      add in class Decimal4
      Parameters:
      s - The scalar of which to add to this quaternion
      Returns:
      The resulting quaternion
    • subtract

      @Nonnull public DecimalQuaternion subtract(@Nonnull BigDecimal s)
      Subtracts this quaternion by a scalar, then returns the resulting quaternion.
      Specified by:
      subtract in interface BigVector<BigDecimal,BigDecimal,Decimal4,Decimal4,Vector4>
      Overrides:
      subtract in class Decimal4
      Parameters:
      s - The scalar of which to subtract this quaternion by
      Returns:
      The resulting quaternion
    • scale

      @Nonnull public DecimalQuaternion scale(@Nonnull BigDecimal s)
      Scales the rotation of this quaternion, then returns the resulting quaternion. This will only work properly if this quaternion is a rotation quaternion. (a quaternion with a Euclidean norm of 1)
      Parameters:
      s - The scale factor to apply to the rotation
      Returns:
      The scaled quaternion
    • divide

      @Nonnull public DecimalQuaternion divide(@Nonnull BigDecimal s) throws ArithmeticException
      Divides this quaternion by a scalar, then returns the resulting quaternion.
      Specified by:
      divide in interface BigVector<BigDecimal,BigDecimal,Decimal4,Decimal4,Vector4>
      Overrides:
      divide in class Decimal4
      Parameters:
      s - The scalar of which to divide each component of this quaternion by
      Returns:
      The resulting quaternion
      Throws:
      ArithmeticException - When the denominator s is zero
    • add

      @Nonnull public DecimalQuaternion add(@Nonnull DecimalQuaternion q)
      Adds another quaternion to this quaternion, then returns the resulting quaternion.
      Parameters:
      q - The quaternion of which to add to this quaternion
      Returns:
      The resulting quaternion
    • subtract

      @Nonnull public DecimalQuaternion subtract(@Nonnull DecimalQuaternion q)
      Subtracts this quaternion by another quaternion, then returns the resulting quaternion.
      Parameters:
      q - The quaternion of which to subtract from this quaternion
      Returns:
      The resulting quaternion
    • multiply

      @Nonnull public DecimalQuaternion multiply(@Nonnull DecimalQuaternion q)
      Multiplies this quaternion by the provided quaternion q.
      Parameters:
      q - The quaternion of which to multiply this quaternion by
      Returns:
      The quaternion left-product of the two quaternions
    • conjugate

      @Nonnull public DecimalQuaternion conjugate()
      Returns the conjugate of this quaternion.
      Returns:
      The conjugate of this quaternion
    • inverse

      @Nonnull public DecimalQuaternion inverse() throws ArithmeticException
      Returns the inverse of this quaternion.
      Returns:
      The inverse of this quaternion
      Throws:
      ArithmeticException - When the squared Euclidean norm (the squared magnitude) of this quaternion is zero
    • negate

      @Nonnull public DecimalQuaternion negate()
      Negates this quaternion, then returns the negated quaternion.
      Specified by:
      negate in interface BigVector<BigDecimal,BigDecimal,Decimal4,Decimal4,Vector4>
      Overrides:
      negate in class Decimal4
      Returns:
      The negation of this quaternion
    • normalize

      @Nonnull public DecimalQuaternion normalize() throws ArithmeticException
      Normalizes this quaternion to have a Euclidean norm (magnitude) of 1.
      Specified by:
      normalize in interface BigVector<BigDecimal,BigDecimal,Decimal4,Decimal4,Vector4>
      Overrides:
      normalize in class Decimal4
      Returns:
      The normalized quaternion of this quaternion
      Throws:
      ArithmeticException - When the Euclidean norm of this quaternion is zero
    • normalizeOrIdentity

      @Nonnull public DecimalQuaternion normalizeOrIdentity()
      Normalizes this quaternion to have a Euclidean norm (magnitude) of 1. If this quaternion has no direction (the Euclidean norm is zero), this will the identity quaternion. (IDENTITY)
      Returns:
      The normalized quaternion of this quaternion if successful, the identity quaternion otherwise
    • normalizeOrDefault

      @Nonnull public DecimalQuaternion normalizeOrDefault(@Nonnull DecimalQuaternion q)
      Normalizes this quaternion to have a Euclidean norm (magnitude) of 1. If this quaternion has no direction (the Euclidean norm is zero), this will return the provided fallback value q instead of throwing an exception.
      Parameters:
      q - The fallback value to default to when normalization is impossible
      Returns:
      The normalized quaternion of this quaternion if successful, the fallback value otherwise