Class: Eigen::Vector3
- Inherits:
-
Object
- Object
- Eigen::Vector3
- Defined in:
- lib/eigen/vector3.rb,
ext/eigen/eigen.cpp
Overview
A 3-vector holding floating-point numbers
Class Method Summary collapse
-
._load(coordinates) ⇒ Object
Support for Marshal.
-
.UnitX ⇒ Object
Returns the (1, 0, 0) unit vector.
-
.UnitY ⇒ Object
Returns the (0, 1, 0) unit vector.
-
.UnitZ ⇒ Object
Returns the (0, 0, 1) unit vector.
-
.Unset ⇒ Object
Returns a vector with all values set to Base.unset.
-
.Zero ⇒ Object
returns the (0, 0, 0) vector.
Instance Method Summary collapse
-
#*(scalar) ⇒ Vector3
Multiplies by a scalar.
-
#+(v) ⇒ Vector3
Sum.
-
#-(v) ⇒ Vector3
Subtracts.
-
#-@ ⇒ Vector3
Negation.
-
#/(scalar) ⇒ Vector3
Divides by a scalar.
-
#==(v) ⇒ Object
Tests for equality.
-
#[](index) ⇒ Numeric
Returns an element.
-
#[]=(index, value) ⇒ Numeric
Sets an element.
-
#_dump(level) ⇒ Object
Support for Marshal.
-
#angle_to(v) ⇒ Object
Returns the angle formed by
self
andv
, oriented fromself
tov
. -
#approx?(v, threshold = dummy_precision) ⇒ Boolean
Verifies that two vectors are within threshold of each other, elementwise.
-
#cross(v) ⇒ VectorX
Cross product.
- #data ⇒ Object
- #data=(value) ⇒ Object
-
#dot(v) ⇒ VectorX
Dot product.
- #dup ⇒ Object
-
#initialize(x = 0, y = 0, z = 0) ⇒ Object
constructor
Creates a new vector.
-
#norm ⇒ Numeric
The vector’s norm.
-
#normalize ⇒ Vector3
Returns a normalized self.
-
#normalize! ⇒ void
Normalizes self.
-
#signed_angle_to(v, axis) ⇒ Object
Computes the signed angle between two vectors, using the provided vector as “positive” rotation direction.
-
#to_a ⇒ Object
Returns the [x, y, z] tuple.
-
#to_qt ⇒ Qt::Quaternion
one.
-
#to_s ⇒ Object
:nodoc:.
-
#x ⇒ Numeric
Returns X.
-
#x=(value) ⇒ Numeric
Sets X.
-
#y ⇒ Numeric
Returns Y.
-
#y=(value) ⇒ Numeric
Sets Y.
-
#z ⇒ Numeric
Returns Z.
-
#z=(value) ⇒ Numeric
Sets Z.
Constructor Details
#initialize(x = 0, y = 0, z = 0) ⇒ Object
Creates a new vector
Class Method Details
._load(coordinates) ⇒ Object
Support for Marshal
68 69 70 |
# File 'lib/eigen/vector3.rb', line 68 def self._load(coordinates) # :nodoc: new(*Marshal.load(coordinates)) end |
.UnitX ⇒ Object
Returns the (1, 0, 0) unit vector
17 18 19 |
# File 'lib/eigen/vector3.rb', line 17 def self.UnitX() return Vector3.new(1, 0, 0) end |
.UnitY ⇒ Object
Returns the (0, 1, 0) unit vector
22 23 24 |
# File 'lib/eigen/vector3.rb', line 22 def self.UnitY() return Vector3.new(0, 1, 0) end |
.UnitZ ⇒ Object
Returns the (0, 0, 1) unit vector
27 28 29 |
# File 'lib/eigen/vector3.rb', line 27 def self.UnitZ() return Vector3.new(0, 0, 1) end |
Instance Method Details
#*(scalar) ⇒ Vector3
Multiplies by a scalar
#+(v) ⇒ Vector3
Sum
#-(v) ⇒ Vector3
Subtracts
#-@ ⇒ Vector3
Negation
#/(scalar) ⇒ Vector3
Divides by a scalar
#==(v) ⇒ Object
Tests for equality
Since Vector3 stores the coordinates as floating-point values, this is a bad test. Use
q.approx?(other_q, tolerance)
instead
57 58 59 60 |
# File 'lib/eigen/vector3.rb', line 57 def ==(v) v.kind_of?(self.class) && __equal__(v) end |
#[](index) ⇒ Numeric
Returns an element
#[]=(index, value) ⇒ Numeric
Sets an element
#_dump(level) ⇒ Object
Support for Marshal
63 64 65 |
# File 'lib/eigen/vector3.rb', line 63 def _dump(level) # :nodoc: Marshal.dump(to_a) end |
#angle_to(v) ⇒ Object
Returns the angle formed by self
and v
, oriented from self
to v
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/eigen/vector3.rb', line 38 def angle_to(v) ret = Math.atan2(v.y, v.x) - Math.atan2(y, x) if ret > Math::PI ret -= 2*Math::PI end if ret < -Math::PI ret += 2*Math::PI end ret end |
#approx?(v, threshold = dummy_precision) ⇒ Boolean
Verifies that two vectors are within threshold of each other, elementwise
#cross(v) ⇒ VectorX
Cross product
#data ⇒ Object
76 77 78 |
# File 'lib/eigen/vector3.rb', line 76 def data [x, y, z] end |
#data=(value) ⇒ Object
80 81 82 |
# File 'lib/eigen/vector3.rb', line 80 def data=(value) self.x,self.y,self.z = value end |
#dot(v) ⇒ VectorX
Dot product
#norm ⇒ Numeric
The vector’s norm
#normalize ⇒ Vector3
Returns a normalized self
#normalize! ⇒ void
This method returns an undefined value.
Normalizes self
#signed_angle_to(v, axis) ⇒ Object
Computes the signed angle between two vectors, using the provided vector as “positive” rotation direction
The returned angle A is so that the rotation defined by A and axis will transform self
into v
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/eigen/vector3.rb', line 160 def signed_angle_to(v, axis) dot_p = self.dot(v) dir = self.cross(v).dot(axis) unsigned = Math.acos(dot_p / norm / v.norm) if dir > 0 return unsigned else return -unsigned end end |
#to_a ⇒ Object
Returns the [x, y, z] tuple
14 |
# File 'lib/eigen/vector3.rb', line 14 def to_a; [x, y, z] end |
#to_qt ⇒ Qt::Quaternion
one
174 175 176 |
# File 'lib/eigen/vector3.rb', line 174 def to_qt Qt::Vector3D.new(x, y, z) end |
#to_s ⇒ Object
:nodoc:
72 73 74 |
# File 'lib/eigen/vector3.rb', line 72 def to_s # :nodoc: "Vector3(#{x}, #{y}, #{z})" end |
#x ⇒ Numeric
Returns X
#x=(value) ⇒ Numeric
Sets X
#y ⇒ Numeric
Returns Y
#y=(value) ⇒ Numeric
Sets Y
#z ⇒ Numeric
Returns Z
#z=(value) ⇒ Numeric
Sets Z