Class: Eigen::Quaternion
- Inherits:
-
Object
- Object
- Eigen::Quaternion
- Defined in:
- lib/eigen/quaternion.rb,
ext/eigen/eigen.cpp
Overview
A floating-point valued quaternion
Class Method Summary collapse
-
._load(coordinates) ⇒ Object
:nodoc:.
-
.from_angle_axis(*args) ⇒ Object
Creates a quaternion from an angle and axis description.
-
.from_euler(*args) ⇒ Object
Creates a quaternion from a set of euler angles.
-
.from_matrix(m) ⇒ Object
Creates a quaternion from a rotation matrix.
-
.from_yaw(yaw) ⇒ Object
The inverse of #yaw.
-
.Identity ⇒ Object
Returns the identity unit quaternion (identity rotation).
-
.Unit ⇒ Object
DEPRECATED: please use identity instead.
Instance Method Summary collapse
-
#*(obj) ⇒ Object
Concatenates with another quaternion or transforms a vector.
-
#==(q) ⇒ Object
Tests for equality.
-
#_dump(level) ⇒ Object
:nodoc:.
-
#approx?(q, threshold = dummy_precision) ⇒ Boolean
Verifies that two quaternions are within threshold of each other, elementwise.
-
#concatenate(q) ⇒ Quaternion
Quaternion multiplication.
- #dup ⇒ Object
-
#from_angle_axis(angle_axis) ⇒ void
Initializes from an angle-axis representation.
-
#from_euler(v) ⇒ void
Initializes from euler angles.
-
#from_matrix(matrix) ⇒ void
Initializes from a rotation matrix.
- #im ⇒ Object
- #im=(value) ⇒ Object
-
#inverse ⇒ Quaternion
The quaternion inverse.
-
#matrix ⇒ MatrixX
The rotation matrix equivalent to this unit quaternion.
-
#norm ⇒ Numeric
The norm.
-
#normalize ⇒ Quaternion
Returns the self normalized.
-
#normalize! ⇒ void
Normalizes self.
- #pitch ⇒ Object
- #re ⇒ Object
- #re=(value) ⇒ Object
- #roll ⇒ Object
-
#to_a ⇒ Object
Returns the quaternion as [w, x, y, z].
-
#to_angle_axis(eps = 1e-12) ⇒ (Float,Vector3)
Returns an angle,axis representation equivalent to this quaternion.
-
#to_euler ⇒ Vector3
Converts this quaternion into Euler-Bryant angles.
-
#to_qt ⇒ Qt::Quaternion
one.
-
#to_s ⇒ Object
:nodoc:.
-
#to_scaled_axis(eps = 1e-12) ⇒ Vector3
Returns a scaled axis representation that is equivalent to this quaternion.
-
#transform(v) ⇒ Vector3
Transform a vector-3 by this quaternion.
-
#w ⇒ Numeric
The real part of the quaternion.
-
#w=(value) ⇒ Numeric
Sets the real part of the quaternion.
-
#x ⇒ Numeric
The first element of the imaginary part of the quaternion.
-
#x=(value) ⇒ Numeric
Sets the first element of the imaginary part of the quaternion.
-
#y ⇒ Numeric
The second element of the imaginary part of the quaternion.
-
#y=(value) ⇒ Numeric
Sets the second element of the imaginary part of the quaternion.
-
#yaw ⇒ Object
Extracts the yaw angle from this quaternion.
-
#z ⇒ Numeric
The third element of the imaginary part of the quaternion.
-
#z=(value) ⇒ Numeric
Sets the third element of the imaginary part of the quaternion.
Class Method Details
._load(coordinates) ⇒ Object
:nodoc:
110 111 112 |
# File 'lib/eigen/quaternion.rb', line 110 def self._load(coordinates) # :nodoc: new(*Marshal.load(coordinates)) end |
.from_angle_axis(*args) ⇒ Object
Creates a quaternion from an angle and axis description
23 24 25 26 27 |
# File 'lib/eigen/quaternion.rb', line 23 def self.from_angle_axis(*args) q = new(1, 0, 0, 0) q.from_angle_axis(*args) q end |
.from_euler(*args) ⇒ Object
Creates a quaternion from a set of euler angles.
See Quaternion#from_euler for details
63 64 65 66 67 |
# File 'lib/eigen/quaternion.rb', line 63 def self.from_euler(*args) q = new(1, 0, 0, 0) q.from_euler(*args) q end |
.from_matrix(m) ⇒ Object
Creates a quaternion from a rotation matrix
70 71 72 73 74 |
# File 'lib/eigen/quaternion.rb', line 70 def self.from_matrix(m) q = new(1, 0, 0, 0) q.from_matrix(m) q end |
.from_yaw(yaw) ⇒ Object
The inverse of #yaw
93 94 95 |
# File 'lib/eigen/quaternion.rb', line 93 def self.from_yaw(yaw) from_euler(Eigen::Vector3.new(yaw, 0, 0), 2, 1, 0) end |
.Identity ⇒ Object
Returns the identity unit quaternion (identity rotation)
12 13 14 |
# File 'lib/eigen/quaternion.rb', line 12 def self.Identity Quaternion.new(1, 0, 0, 0) end |
.Unit ⇒ Object
DEPRECATED: please use identity instead. Returns the unit quaternion (identity rotation)
17 18 19 20 |
# File 'lib/eigen/quaternion.rb', line 17 def self.Unit warn "[DEPRECATED] Quaternion.unit, please use Quaternion.identity." self.Identity end |
Instance Method Details
#*(obj) ⇒ Object
Concatenates with another quaternion or transforms a vector
98 99 100 101 102 103 104 |
# File 'lib/eigen/quaternion.rb', line 98 def *(obj) if obj.kind_of?(Quaternion) concatenate(obj) else transform(obj) end end |
#==(q) ⇒ Object
Tests for equality
Since Quaternion stores the coordinates as floating-point values, this is a bad test. Use
(v - other_v).norm < threshold
instead
126 127 128 129 |
# File 'lib/eigen/quaternion.rb', line 126 def ==(q) q.kind_of?(self.class) && __equal__(q) end |
#_dump(level) ⇒ Object
:nodoc:
106 107 108 |
# File 'lib/eigen/quaternion.rb', line 106 def _dump(level) # :nodoc: Marshal.dump(to_a) end |
#approx?(q, threshold = dummy_precision) ⇒ Boolean
Verifies that two quaternions are within threshold of each other, elementwise
#concatenate(q) ⇒ Quaternion
Quaternion multiplication
#dup ⇒ Object
4 5 6 |
# File 'lib/eigen/quaternion.rb', line 4 def dup Quaternion.new(w, x, y, z) end |
#from_angle_axis(angle_axis) ⇒ void
This method returns an undefined value.
Initializes from an angle-axis representation
#from_euler(v) ⇒ void
This method returns an undefined value.
Initializes from euler angles
#from_matrix(matrix) ⇒ void
This method returns an undefined value.
Initializes from a rotation matrix
#im ⇒ Object
139 140 141 |
# File 'lib/eigen/quaternion.rb', line 139 def im [x,y,z] end |
#im=(value) ⇒ Object
143 144 145 |
# File 'lib/eigen/quaternion.rb', line 143 def im=(value) self.x, self.y, self.z = *value end |
#inverse ⇒ Quaternion
The quaternion inverse
#matrix ⇒ MatrixX
The rotation matrix equivalent to this unit quaternion
#norm ⇒ Numeric
The norm
#normalize ⇒ Quaternion
Returns the self normalized
#normalize! ⇒ void
This method returns an undefined value.
Normalizes self
#pitch ⇒ Object
84 85 86 |
# File 'lib/eigen/quaternion.rb', line 84 def pitch to_euler[1] end |
#re ⇒ Object
131 132 133 |
# File 'lib/eigen/quaternion.rb', line 131 def re w end |
#re=(value) ⇒ Object
135 136 137 |
# File 'lib/eigen/quaternion.rb', line 135 def re=(value) self.w = value end |
#roll ⇒ Object
88 89 90 |
# File 'lib/eigen/quaternion.rb', line 88 def roll to_euler[2] end |
#to_a ⇒ Object
Returns the quaternion as [w, x, y, z]
9 |
# File 'lib/eigen/quaternion.rb', line 9 def to_a; [w, x, y, z] end |
#to_angle_axis(eps = 1e-12) ⇒ (Float,Vector3)
Returns an angle,axis representation equivalent to this quaternion
If the angle turns out to be PI, there are two solutions and the one with positive Z component is chosen.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/eigen/quaternion.rb', line 38 def to_angle_axis(eps = 1e-12) w, x, y, z = to_a norm = Math.sqrt(x*x+y*y+z*z); if norm < eps return 0, Eigen::Vector3.new(0,0,1); end angle = 2.0 * Math.atan2(norm, w); axis = Eigen::Vector3.new(x, y, z) / norm return angle, axis end |
#to_euler ⇒ Vector3
Converts this quaternion into Euler-Bryant angles
#to_qt ⇒ Qt::Quaternion
one
248 249 250 |
# File 'lib/eigen/quaternion.rb', line 248 def to_qt Qt::Quaternion.new(w, x, y, z) end |
#to_s ⇒ Object
:nodoc:
114 115 116 |
# File 'lib/eigen/quaternion.rb', line 114 def to_s # :nodoc: "Quaternion(#{w}, (#{x}, #{y}, #{z}))" end |
#to_scaled_axis(eps = 1e-12) ⇒ Vector3
Returns a scaled axis representation that is equivalent to this quaternion
55 56 57 58 |
# File 'lib/eigen/quaternion.rb', line 55 def to_scaled_axis(eps = 1e-12) angle, axis = to_angle_axis(eps) return axis * angle end |
#transform(v) ⇒ Vector3
Transform a vector-3 by this quaternion
#w ⇒ Numeric
The real part of the quaternion
#w=(value) ⇒ Numeric
Sets the real part of the quaternion
#x ⇒ Numeric
The first element of the imaginary part of the quaternion
#x=(value) ⇒ Numeric
Sets the first element of the imaginary part of the quaternion
#y ⇒ Numeric
The second element of the imaginary part of the quaternion
#y=(value) ⇒ Numeric
Sets the second element of the imaginary part of the quaternion
#yaw ⇒ Object
Extracts the yaw angle from this quaternion
It decomposes the quaternion in euler angles using to_euler and returns the first element. See #to_euler for details.
80 81 82 |
# File 'lib/eigen/quaternion.rb', line 80 def yaw to_euler[0] end |
#z ⇒ Numeric
The third element of the imaginary part of the quaternion
#z=(value) ⇒ Numeric
Sets the third element of the imaginary part of the quaternion