Class Eymiha::Quaternion
In: lib/eymiha/math3/quaternion.rb
Parent: Object

Quaternion instances represents Quaternions, complex numbers with one real part and three imaginary parts. While the math is a bit obscure, they can be used to manipulate 3D rotations without "gimbal lock", the problem of coincident viewing angle alignment problems at the boundaries, for example, where the difference between the x and y coordinates of the viewing vector are zero (ie. looking straight up or straight down.)

Interestingly, Quaternions were first conceptualized by Hamilton in 1843, well before the widespread use of vector notation. While mostly put on the shelf, they still solve certain problems elegantly, and in some cases more quickly than matrix-based 3D calulations.

The quaternion‘s real part is accessed through the real instance variable, the three complex parts as the quaternion‘s "axis" vector, a Point3.

Methods

*   +   -   ==   =~   abs   add   add!   approximately_equals?   conjugate   conjugate!   divide   divide!   from_axis_angle   inverse   inverse!   multiply   multiply!   new   norm   quaternion   scale   scale!   set   subtract   subtract!   to_axis_angle   to_s  

Included Modules

ThreeDimensions

Attributes

axis  [RW]  complex axis vector part reader and writer
real  [RW]  real part reader and writer

Public Class methods

Returns a new Quaternion-based encoding of a rotation.

Creates and returns a Quaternion instance. Sets the coordinates values using the set method.

Public Instance methods

*(axis=origin,real=1)

Alias for multiply

+(axis=origin,real=0)

Alias for add

-(axis=origin,real=0)

Alias for subtract

Returns true if the parts of the instance are equal to the parts of the given quaternion.

=~(quaternion,epsilon=Numeric.epsilon)

Alias for approximately_equals?

Returns the absolute value of the instance.

Returns a new Quaternion instance whose parts are the original instance‘s with the given amounts added:

  • axis is a Quaternion, its parts are added.
  • axis responds like a Point3, the arguments are added.
  • otherwise a TypeError is raised.

Returns the modified instance with the arguments added.

Returns true if the parts of the instance are approximately equal to the parts of the given quaternion, each part less than a distance epsilon from the target.

Returns a new Quaternion instance that is the conjugate of the original instance.

Returns the modified instance replaced with its conjugate.

Returns a new Quaternion instance whose parts are the original instance‘s divided by the given amounts:

  • axis is a Quaternion, the instance is divided by the axis’ parts.
  • axis responds like a Point3, the instance is divided by the arguments.
  • otherwise a TypeError is raised.

Returns the modified instance divided by the arguments.

Returns a new Quaternion instance that is the inverse of the original instance.

Returns the modified instance replaced with its inverse.

Returns a new Quaternion instance whose parts are the original instance‘s multiplied by the given amounts:

  • axis is a Quaternion, the instance is multiplied by the axis’ parts.
  • axis responds like a Point3, the instance is multiplied by the arguments.
  • otherwise a TypeError is raised.

Returns the modified instance multiplied by the arguments.

Returns the norm of the instance.

Returns a copy of a Quaternion with the given parts:

  • axis is a Quaternion, its parts are copied.
  • axis responds like a Point3, the arguments are copied.
  • otherwise a TypeError is raised.

Returns a new Quaternion instance whose parts are the original instance‘s multiplied by the scalar:

  • scalar is a Quaternion, the instance is multiplied by the scalar‘s parts.
  • axis is a Numeric, the instance‘s parts are multiplied by the scalar.
  • otherwise a TypeError is raised.

Returns the modified instance multiplied by the scalar.

Sets the axis and real values of the instance. When

  • axis is a Quaternion, the arguments are interpretted as the parts of a quaternion.
  • axis reponds like a Point3, the axis and real are used to set the quaternion‘s values.
  • otherwise a TypeError is raised.

The modified instance is returned.

Returns a new Quaternion instance whose parts are the original instance‘s with the given amounts subtracted:

  • axis is a Quaternion, its parts are subtracted.
  • axis responds like a Point3, the arguments are subtracted.
  • otherwise a TypeError is raised.

Returns the modified instance with the arguments subtracted.

Returns a new Quaternion encoded into a rotation.

Returns a string representation of the instance.

[Validate]