Class: Eigen::Vector3

Inherits:
Object
  • Object
show all
Defined in:
lib/eigen/vector3.rb,
ext/eigen/eigen.cpp

Overview

A 3-vector holding floating-point numbers

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x = 0, y = 0, z = 0) ⇒ Object

Creates a new vector

Parameters:

  • x (Numeric) (defaults to: 0)
  • y (Numeric) (defaults to: 0)
  • z (Numeric) (defaults to: 0)

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

.UnitXObject

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

.UnitYObject

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

.UnitZObject

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

.UnsetObject

Returns a vector with all values set to Base.unset



5
6
7
# File 'lib/eigen/vector3.rb', line 5

def self.Unset
    return Vector3.new(Base.unset, Base.unset, Base.unset)
end

.ZeroObject

returns the (0, 0, 0) vector



32
33
34
# File 'lib/eigen/vector3.rb', line 32

def self.Zero()
    return Vector3.new(0, 0, 0)
end

Instance Method Details

#*(scalar) ⇒ Vector3

Multiplies by a scalar

Parameters:

  • scalar (Numeric)

    the scalar

Returns:

#+(v) ⇒ Vector3

Sum

Parameters:

Returns:

#-(v) ⇒ Vector3

Subtracts

Parameters:

Returns:

#-@Vector3

Negation

Returns:

#/(scalar) ⇒ Vector3

Divides by a scalar

Parameters:

  • scalar (Numeric)

    the scalar

Returns:

#==(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

Parameters:

  • index (Integer)

    the element index (0, 1 or 2)

Returns:

  • (Numeric)

#[]=(index, value) ⇒ Numeric

Sets an element

Parameters:

  • index (Integer)

    the element index (0, 1 or 2)

  • value (Numeric)

Returns:

  • (Numeric)

#_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

Parameters:

Returns:

  • (Boolean)

#cross(v) ⇒ VectorX

Cross product

Parameters:

Returns:

#dataObject



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

Parameters:

Returns:

#dupObject



9
10
11
# File 'lib/eigen/vector3.rb', line 9

def dup
    Vector3.new(x, y, z)
end

#normNumeric

The vector’s norm

Returns:

  • (Numeric)

#normalizeVector3

Returns a normalized self

Returns:

#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_aObject

Returns the [x, y, z] tuple



14
# File 'lib/eigen/vector3.rb', line 14

def to_a; [x, y, z] end

#to_qtQt::Quaternion

one

Returns:

  • (Qt::Quaternion)

    the Qt vector that is identical to this



174
175
176
# File 'lib/eigen/vector3.rb', line 174

def to_qt
    Qt::Vector3D.new(x, y, z)
end

#to_sObject

:nodoc:



72
73
74
# File 'lib/eigen/vector3.rb', line 72

def to_s # :nodoc:
    "Vector3(#{x}, #{y}, #{z})"
end

#xNumeric

Returns X

Returns:

  • (Numeric)

#x=(value) ⇒ Numeric

Sets X

Parameters:

  • value (Numeric)

Returns:

  • (Numeric)

#yNumeric

Returns Y

Returns:

  • (Numeric)

#y=(value) ⇒ Numeric

Sets Y

Parameters:

  • value (Numeric)

Returns:

  • (Numeric)

#zNumeric

Returns Z

Returns:

  • (Numeric)

#z=(value) ⇒ Numeric

Sets Z

Parameters:

  • value (Numeric)

Returns:

  • (Numeric)