class Roby::Pos::Vector3D

A (x, y, z) vector

Attributes

x[RW]

The vector coordinates

y[RW]

The vector coordinates

z[RW]

The vector coordinates

Public Class Methods

new(x = 0, y = 0, z = 0) click to toggle source

Initializes a 3D vector

# File lib/roby/state/pos.rb, line 8
def initialize(x = 0, y = 0, z = 0)
    @x, @y, @z = x, y, z
end

Public Instance Methods

*(a) click to toggle source

Returns the product of this vector with the scalar a

# File lib/roby/state/pos.rb, line 26
def *(a); Vector3D.new(x * a, y * a, z * a) end
+(v) click to toggle source

Returns self + v

# File lib/roby/state/pos.rb, line 22
def +(v); Vector3D.new(x + v.x, y + v.y, z + v.z) end
-(v) click to toggle source

Returns self - v

# File lib/roby/state/pos.rb, line 24
def -(v); Vector3D.new(x - v.x, y - v.y, z - v.z) end
-@() click to toggle source

Returns the opposite of this vector

# File lib/roby/state/pos.rb, line 30
def -@; Vector3D.new(-x, -y, -z) end
/(a) click to toggle source

Returns the division of this vector with the scalar a

# File lib/roby/state/pos.rb, line 28
def /(a); Vector3D.new(x / a, y / a, z / a) end
==(v) click to toggle source

True if v is the same vector than self

# File lib/roby/state/pos.rb, line 35
def ==(v)
    v.kind_of?(Vector3D) &&
        v.x == x && v.y == y && v.z == z
end
distance2d w click to toggle source
distance2d x, y
distance2d x, y, z

Returns the euclidian distance in the (X,Y,Z) space, between this vector and the given coordinates. In the first form, w can be a vector in which case the distance is computed between (self.x, self.y, self.z) and (w.x, w.y, w.z). If w is a scalar, it is taken as the X coordinate and y = z = 0.

In the second form, both x and y must be scalars and z == 0.

# File lib/roby/state/pos.rb, line 77
def distance(x = 0, y = nil, z = nil)
    if !y && x.respond_to?(:x)
        x, y, z = x.x, x.y, x.z
    else
        y ||= 0
        z ||= 0
    end

    Math.sqrt( (x - self.x) ** 2 + (y - self.y) ** 2 + (z - self.z) ** 2)
end
distance2d w click to toggle source
distance2d x, y

Returns the euclidian distance in the (X,Y) plane, between this vector and the given coordinates. In the first form, w can be a vector in which case the distance is computed between (self.x, self.y) and (w.x, w.y). If w is a scalar, it is taken as the X coordinate and y = 0.

In the second form, both x and y must be scalars.

# File lib/roby/state/pos.rb, line 56
def distance2d(x = 0, y = nil)
    if !y && x.respond_to?(:x)
        x, y = x.x, x.y
    else
        y ||= 0
    end

    Math.sqrt( (x - self.x) ** 2 + (y - self.y) ** 2 )
end
length() click to toggle source

The length of the vector

# File lib/roby/state/pos.rb, line 20
def length; distance(0, 0, 0) end
null?(tolerance = 0) click to toggle source

True if this vector is of zero length. If tolerance is non-zero, returns true if length <= tolerance.

# File lib/roby/state/pos.rb, line 42
def null?(tolerance = 0)
    length <= tolerance
end
pretty_print(pp) click to toggle source
# File lib/roby/state/pos.rb, line 15
def pretty_print(pp)
    pp.text to_s
end
xyz() click to toggle source

Returns the [x, y, z] array

# File lib/roby/state/pos.rb, line 33
def xyz; [x, y, z] end