Class: Numerix::Quaternion

Inherits:
Structure show all
Defined in:
lib/numerix/quaternion.rb

Overview

A structure encapsulating a four-dimensional vector (x,y,z,w), which is used to efficiently rotate an object about the (x,y,z) vector by the angle theta, where w = cos(theta / 2).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Structure

#[], #[]=, #address, #dup, #each, #pack, #ptr, size, unpack

Constructor Details

#initializeQuaternion #initialize(x, y, z, w) ⇒ Quaternion #initialize(vector, scalar) ⇒ Quaternion

Returns a new instance of Quaternion.

Overloads:

  • #initializeQuaternion

    Constructs a default quaternion with all components set to 0.0.

  • #initialize(x, y, z, w) ⇒ Quaternion

    Constructs a Quaternion from the given components.

    Parameters:

    • x (Float)

      The X component of the quaternion.

    • y (Float)

      The Y component of the quaternion.

    • z (Float)

      The Z component of the quaternion.

    • w (Float)

      The W component of the quaternion.

  • #initialize(vector, scalar) ⇒ Quaternion

    Constructs a Quaternion from the given vector and rotation parts.

    Parameters:

    • vector (Vector3)

      The vector part of the quaternion.

    • scalar (Float)

      The rotation part of the quaternion.



43
44
# File 'lib/numerix/quaternion.rb', line 43

def initialize(*args) # TODO

end

Instance Attribute Details

#wFloat

Returns the rotation component of the quaternion.

Returns:

  • (Float)

    the rotation component of the quaternion.



23
24
25
# File 'lib/numerix/quaternion.rb', line 23

def w
  @w
end

#xFloat

Returns the X-value of the quaternion component of the quaternion.

Returns:

  • (Float)

    the X-value of the quaternion component of the quaternion.



11
12
13
# File 'lib/numerix/quaternion.rb', line 11

def x
  @x
end

#yFloat

Returns the Y-value of the quaternion component of the quaternion.

Returns:

  • (Float)

    the Y-value of the quaternion component of the quaternion.



15
16
17
# File 'lib/numerix/quaternion.rb', line 15

def y
  @y
end

#zFloat

Returns the Z-value of the quaternion component of the quaternion.

Returns:

  • (Float)

    the Z-value of the quaternion component of the quaternion.



19
20
21
# File 'lib/numerix/quaternion.rb', line 19

def z
  @z
end

Class Method Details

.from_axis_angle(axis, angle) ⇒ Quaternion

Creates a quaternion from a vector and an angle to rotate about the vector.

Parameters:

  • axis (Vector3)

    The vector to rotate around.

  • angle (Float)

    The angle, in radians, to rotate around the vector.

Returns:



304
305
# File 'lib/numerix/quaternion.rb', line 304

def from_axis_angle(axis, angle)
end

.from_rotation_matrix(matrix) ⇒ Quaternion

Creates a quaternion from the given rotation matrix.

Parameters:

Returns:



325
326
# File 'lib/numerix/quaternion.rb', line 325

def from_rotation_matrix(matrix)
end

.from_yaw_pitch_roll(yaw, pitch, roll) ⇒ Quaternion

Creates a new quaternion from the given yaw, pitch, and roll, in radians.

Parameters:

  • yaw (Float)

    The yaw angle, in radians, around the Y-axis.

  • pitch (Float)

    The pitch angle, in radians, around the X-axis.

  • roll (Float)

    The roll angle, in radians, around the Z-axis.

Returns:



316
317
# File 'lib/numerix/quaternion.rb', line 316

def from_yaw_pitch_roll(yaw, pitch, roll)
end

.identityQuaternion

Returns a quaternion representing no rotation.

Returns:

  • (Quaternion)

    a quaternion representing no rotation.



293
294
# File 'lib/numerix/quaternion.rb', line 293

def identity
end

.lerp(quaternion1, quaternion2, amount) ⇒ Quaternion

Linearly interpolates between two quaternions based on the given weighting.

Parameters:

  • quaternion1 (Quaternion)

    The first source quaternion.

  • quaternion2 (Quaternion)

    The second source quaternion.

  • amount (Float)

    Value between 0.0 and 1.0 indicating the weight of the second source quaternion.

Returns:



351
352
# File 'lib/numerix/quaternion.rb', line 351

def lerp(quaternion1, quaternion2, amount)
end

.slerp(quaternion1, quaternion2, amount) ⇒ Quaternion

Interpolates between two quaternions, using spherical linear interpolation.

Parameters:

  • quaternion1 (Quaternion)

    The first source quaternion.

  • quaternion2 (Quaternion)

    The second source quaternion.

  • amount (Float)

    Value between 0.0 and 1.0 indicating the weight of the second source quaternion.

Returns:



338
339
# File 'lib/numerix/quaternion.rb', line 338

def slerp(quaternion1, quaternion2, amount)
end

Instance Method Details

#*(scalar) ⇒ Quaternion #*(other) ⇒ Quaternion

Quaternion multiplication.

Overloads:

  • #*(scalar) ⇒ Quaternion

    Scalar quaternion multiplication.

    Parameters:

    • scalar (Float)

      The scalar value.

  • #*(other) ⇒ Quaternion

    Multiplies this quaternion by another.

    Parameters:

    • other (Quaternion)

      The source quaternion to multiply.

Returns:



260
261
# File 'lib/numerix/quaternion.rb', line 260

def *(other)
end

#+(other) ⇒ Quaternion

Adds this quaternion with another.

Parameters:

Returns:



235
236
# File 'lib/numerix/quaternion.rb', line 235

def +(other)
end

#-(other) ⇒ Quaternion

Gets the difference of this quaternion and another.

Parameters:

  • other (Quaternion)

    The quaternion to subtract.

Returns:

  • (Quaternion)

    the difference of the quaternions.



243
244
# File 'lib/numerix/quaternion.rb', line 243

def -(other)
end

#-@Quaternion

Performs unary negation on this quaternion instance.

Returns:

  • (Quaternion)

    the vector with swapped +/- values.



226
227
# File 'lib/numerix/quaternion.rb', line 226

def -@
end

#*(scalar) ⇒ Quaternion #*(other) ⇒ Quaternion

Quaternion division.

Overloads:

  • #*(scalar) ⇒ Quaternion

    Scalar quaternion division.

    Parameters:

    • scalar (Float)

      The scalar value.

  • #*(other) ⇒ Quaternion

    Divides this quaternion by another.

    Parameters:

    • other (Quaternion)

      The source quaternion to divide.

Returns:



277
278
# File 'lib/numerix/quaternion.rb', line 277

def /(other)
end

#==(other) ⇒ Boolean

Returns flag if this quaternion instance is equal to the given object.

Parameters:

  • other (Object)

    The object to compare.

Returns:

  • (Boolean)

    true if objects are equal, otherwise false.



286
287
# File 'lib/numerix/quaternion.rb', line 286

def ==(other)
end

#concatenate(other) ⇒ Quaternion

Concatenates this quaternion and another, the result represents the this rotation followed by the given quaternion's rotation.

Parameters:

  • other (Quaternion)

    The rotation to add in the series.

Returns:

  • (Quaternion)

    a new quaternion representing the concatenation this rotation followed by the other rotation.

See Also:



122
123
# File 'lib/numerix/quaternion.rb', line 122

def concatenate(other)
end

#concatenate!(other) ⇒ self

Note:

This function is identical to #concatenate, but alters the values of this instance without creating a new object.

Concatenates this quaternion and another, the result represents the this rotation followed by the given quaternion's rotation.

Parameters:

  • other (Quaternion)

    The rotation to add in the series.

Returns:

  • (self)

See Also:



137
138
# File 'lib/numerix/quaternion.rb', line 137

def concatenate!(other)
end

#conjugateQuaternion

Creates the conjugate of this quaternion.

Returns:

  • (Quaternion)

    the conjugate of the os instance.

See Also:



86
87
# File 'lib/numerix/quaternion.rb', line 86

def conjugate
end

#conjugate!self

Alters this instance to be its conjugate.

Returns:

  • (self)

See Also:



95
96
# File 'lib/numerix/quaternion.rb', line 95

def conjugate!
end

#dot(other) ⇒ Float

Calculates the dot product of two quaternions.

Parameters:

  • other (Quaternion)

    The source quaternion to compute product from.

Returns:

  • (Float)

    the dot product of the quaternions.



109
110
# File 'lib/numerix/quaternion.rb', line 109

def dot(other)
end

#identity?Boolean

Returns true if the quaternion is the identity quaternion, otherwise false.

Returns:

  • (Boolean)

    true if the quaternion is the identity quaternion, otherwise false.



49
50
# File 'lib/numerix/quaternion.rb', line 49

def identity?
end

#inverseQuaternion

Returns the inverse of this quaternion.

Returns:

  • (Quaternion)

    the inverse of this quaternion.



100
101
# File 'lib/numerix/quaternion.rb', line 100

def inverse
end

#lengthFloat Also known as: magnitude

Returns the length of the quaternion.

Returns:

  • (Float)

    the length of the quaternion.



54
55
# File 'lib/numerix/quaternion.rb', line 54

def length
end

#length_squaredFloat

Returns the length of the quaternion squared.

Returns:

  • (Float)

    the length of the quaternion squared.



61
62
# File 'lib/numerix/quaternion.rb', line 61

def length_squared
end

#lerp(quaternion, amount) ⇒ Quaternion

Linearly interpolates between this quaternion and another based on the given weighting.

Parameters:

  • quaternion (Quaternion)

    The source quaternion to interpolate between.

  • amount (Float)

    Value between 0.0 and 1.0 indicating the weight of the given quaternion.

Returns:

See Also:



152
153
# File 'lib/numerix/quaternion.rb', line 152

def lerp(quaternion, amount)
end

#lerp!(quaternion, amount) ⇒ self

Linearly interpolates between this quaternion and another based on the given weighting, altering the values of this quaternion.

Parameters:

  • quaternion (Quaternion)

    The source quaternion to interpolate between.

  • amount (Float)

    Value between 0.0 and 1.0 indicating the weight of the given quaternion.

Returns:

  • (self)

See Also:



166
167
# File 'lib/numerix/quaternion.rb', line 166

def lerp!(quaternion, amount)
end

#normalizeQuaternion

Returns a new quaternion with the same direction as the given quaternion, but with a length of 1.0.

Returns:



69
70
# File 'lib/numerix/quaternion.rb', line 69

def normalize
end

#normalize!self

Alters this quaternion instance to maintain same direction, but adjust values so that quaternion has a length of 1.0.

Returns:

  • (self)


77
78
# File 'lib/numerix/quaternion.rb', line 77

def normalize!
end

#slerp(quaternion, amount) ⇒ Quaternion

Interpolates between this quaternion and another using spherical linear interpolation.

Parameters:

  • quaternion (Quaternion)

    The source quaternion to interpolate between.

  • amount (Float)

    Value between 0.0 and 1.0 indicating the weight of the given quaternion.

Returns:

See Also:



180
181
# File 'lib/numerix/quaternion.rb', line 180

def slerp(quaternion, amount)
end

#slerp!(quaternion, amount) ⇒ self

Note:

This function is identical to #slerp, but alters the values of this instance without creating a new object.

Interpolates between this quaternion and another using spherical linear interpolation.

Parameters:

  • quaternion (Quaternion)

    The source quaternion to interpolate between.

  • amount (Float)

    Value between 0.0 and 1.0 indicating the weight of the given quaternion.

Returns:

  • (self)

See Also:



197
198
# File 'lib/numerix/quaternion.rb', line 197

def slerp!(quaternion, amount)
end

#to_aArray<Float> Also known as: elements

Returns an Array representation of this instance.

Returns:

  • (Array<Float>)

    an Array representation of this instance.



207
208
# File 'lib/numerix/quaternion.rb', line 207

def to_a
end

#to_hHash{Symbol => Float}

Returns a Hash representation of this instance.

Returns:

  • (Hash{Symbol => Float})

    a Hash representation of this instance.



214
215
# File 'lib/numerix/quaternion.rb', line 214

def to_h
end

#to_sString

Returns a String representation of this instance.

Returns:

  • (String)

    a String representation of this instance.



202
203
# File 'lib/numerix/quaternion.rb', line 202

def to_s
end

#to_vec4Vector4

Returns a Vector4 representation of this instance.

Returns:



219
220
# File 'lib/numerix/quaternion.rb', line 219

def to_vec4
end