Class: Numerix::Quaternion
- 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
-
#w ⇒ Float
The rotation component of the quaternion.
-
#x ⇒ Float
The X-value of the quaternion component of the quaternion.
-
#y ⇒ Float
The Y-value of the quaternion component of the quaternion.
-
#z ⇒ Float
The Z-value of the quaternion component of the quaternion.
Class Method Summary collapse
-
.from_axis_angle(axis, angle) ⇒ Quaternion
Creates a quaternion from a vector and an angle to rotate about the vector.
-
.from_rotation_matrix(matrix) ⇒ Quaternion
Creates a quaternion from the given rotation matrix.
-
.from_yaw_pitch_roll(yaw, pitch, roll) ⇒ Quaternion
Creates a new quaternion from the given yaw, pitch, and roll, in radians.
-
.identity ⇒ Quaternion
A quaternion representing no rotation.
-
.lerp(quaternion1, quaternion2, amount) ⇒ Quaternion
Linearly interpolates between two quaternions based on the given weighting.
-
.slerp(quaternion1, quaternion2, amount) ⇒ Quaternion
Interpolates between two quaternions, using spherical linear interpolation.
Instance Method Summary collapse
-
#*(other) ⇒ Quaternion
Quaternion multiplication.
-
#+(other) ⇒ Quaternion
Adds this quaternion with another.
-
#-(other) ⇒ Quaternion
Gets the difference of this quaternion and another.
-
#-@ ⇒ Quaternion
Performs unary negation on this quaternion instance.
-
#/(other) ⇒ Quaternion
Quaternion division.
-
#==(other) ⇒ Boolean
Returns flag if this quaternion instance is equal to the given object.
-
#concatenate(other) ⇒ Quaternion
Concatenates this quaternion and another, the result represents the this rotation followed by the given quaternion's rotation.
-
#concatenate!(other) ⇒ self
Concatenates this quaternion and another, the result represents the this rotation followed by the given quaternion's rotation.
-
#conjugate ⇒ Quaternion
Creates the conjugate of this quaternion.
-
#conjugate! ⇒ self
Alters this instance to be its conjugate.
-
#dot(other) ⇒ Float
Calculates the dot product of two quaternions.
-
#identity? ⇒ Boolean
trueif the quaternion is the identity quaternion, otherwisefalse. -
#initialize(*args) ⇒ Quaternion
constructor
A new instance of Quaternion.
-
#inverse ⇒ Quaternion
The inverse of this quaternion.
-
#length ⇒ Float
(also: #magnitude)
The length of the quaternion.
-
#length_squared ⇒ Float
The length of the quaternion squared.
-
#lerp(quaternion, amount) ⇒ Quaternion
Linearly interpolates between this quaternion and another based on the given weighting.
-
#lerp!(quaternion, amount) ⇒ self
Linearly interpolates between this quaternion and another based on the given weighting, altering the values of this quaternion.
-
#normalize ⇒ Quaternion
Returns a new quaternion with the same direction as the given quaternion, but with a length of
1.0. -
#normalize! ⇒ self
Alters this quaternion instance to maintain same direction, but adjust values so that quaternion has a length of
1.0. -
#slerp(quaternion, amount) ⇒ Quaternion
Interpolates between this quaternion and another using spherical linear interpolation.
-
#slerp!(quaternion, amount) ⇒ self
Interpolates between this quaternion and another using spherical linear interpolation.
-
#to_a ⇒ Array<Float>
(also: #elements)
An Array representation of this instance.
-
#to_h ⇒ Hash{Symbol => Float}
A Hash representation of this instance.
-
#to_s ⇒ String
A String representation of this instance.
-
#to_vec4 ⇒ Vector4
A Vector4 representation of this instance.
Methods inherited from Structure
#[], #[]=, #address, #dup, #each, #pack, #ptr, size, unpack
Constructor Details
#initialize ⇒ Quaternion #initialize(x, y, z, w) ⇒ Quaternion #initialize(vector, scalar) ⇒ Quaternion
Returns a new instance of Quaternion.
43 44 |
# File 'lib/numerix/quaternion.rb', line 43 def initialize(*args) # TODO end |
Instance Attribute Details
#w ⇒ Float
Returns the rotation component of the quaternion.
23 24 25 |
# File 'lib/numerix/quaternion.rb', line 23 def w @w end |
#x ⇒ Float
Returns the X-value of the quaternion component of the quaternion.
11 12 13 |
# File 'lib/numerix/quaternion.rb', line 11 def x @x end |
#y ⇒ Float
Returns the Y-value of the quaternion component of the quaternion.
15 16 17 |
# File 'lib/numerix/quaternion.rb', line 15 def y @y end |
#z ⇒ Float
Returns 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.
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.
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.
316 317 |
# File 'lib/numerix/quaternion.rb', line 316 def from_yaw_pitch_roll(yaw, pitch, roll) end |
.identity ⇒ Quaternion
Returns 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.
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.
338 339 |
# File 'lib/numerix/quaternion.rb', line 338 def slerp(quaternion1, quaternion2, amount) end |
Instance Method Details
#*(scalar) ⇒ Quaternion #*(other) ⇒ Quaternion
Quaternion multiplication.
260 261 |
# File 'lib/numerix/quaternion.rb', line 260 def *(other) end |
#+(other) ⇒ Quaternion
Adds this quaternion with another.
235 236 |
# File 'lib/numerix/quaternion.rb', line 235 def +(other) end |
#-(other) ⇒ Quaternion
Gets the difference of this quaternion and another.
243 244 |
# File 'lib/numerix/quaternion.rb', line 243 def -(other) end |
#-@ ⇒ Quaternion
Performs unary negation on this quaternion instance.
226 227 |
# File 'lib/numerix/quaternion.rb', line 226 def -@ end |
#*(scalar) ⇒ Quaternion #*(other) ⇒ Quaternion
Quaternion division.
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.
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.
122 123 |
# File 'lib/numerix/quaternion.rb', line 122 def concatenate(other) end |
#concatenate!(other) ⇒ self
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.
137 138 |
# File 'lib/numerix/quaternion.rb', line 137 def concatenate!(other) end |
#conjugate ⇒ Quaternion
Creates the conjugate of this quaternion.
86 87 |
# File 'lib/numerix/quaternion.rb', line 86 def conjugate end |
#conjugate! ⇒ self
Alters this instance to be its conjugate.
95 96 |
# File 'lib/numerix/quaternion.rb', line 95 def conjugate! end |
#dot(other) ⇒ Float
Calculates the dot product of two 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.
49 50 |
# File 'lib/numerix/quaternion.rb', line 49 def identity? end |
#inverse ⇒ Quaternion
Returns the inverse of this quaternion.
100 101 |
# File 'lib/numerix/quaternion.rb', line 100 def inverse end |
#length ⇒ Float Also known as: magnitude
Returns the length of the quaternion.
54 55 |
# File 'lib/numerix/quaternion.rb', line 54 def length end |
#length_squared ⇒ Float
Returns 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.
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.
166 167 |
# File 'lib/numerix/quaternion.rb', line 166 def lerp!(quaternion, amount) end |
#normalize ⇒ Quaternion
Returns a new quaternion with the same direction as the given quaternion,
but with a length of 1.0.
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.
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.
180 181 |
# File 'lib/numerix/quaternion.rb', line 180 def slerp(quaternion, amount) end |
#slerp!(quaternion, amount) ⇒ self
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.
197 198 |
# File 'lib/numerix/quaternion.rb', line 197 def slerp!(quaternion, amount) end |
#to_a ⇒ Array<Float> Also known as: elements
Returns an Array representation of this instance.
207 208 |
# File 'lib/numerix/quaternion.rb', line 207 def to_a end |
#to_h ⇒ Hash{Symbol => Float}
Returns a Hash representation of this instance.
214 215 |
# File 'lib/numerix/quaternion.rb', line 214 def to_h end |
#to_s ⇒ String
Returns a String representation of this instance.
202 203 |
# File 'lib/numerix/quaternion.rb', line 202 def to_s end |