class Roby::Pos::Vector3D
A (x, y, z) vector
Attributes
The vector coordinates
The vector coordinates
The vector coordinates
Public Class Methods
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
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
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
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
Returns the opposite of this vector
# File lib/roby/state/pos.rb, line 30 def -@; Vector3D.new(-x, -y, -z) end
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
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
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
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
The length of the vector
# File lib/roby/state/pos.rb, line 20 def length; distance(0, 0, 0) end
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
# File lib/roby/state/pos.rb, line 15 def pretty_print(pp) pp.text to_s end
Returns the [x, y, z] array
# File lib/roby/state/pos.rb, line 33 def xyz; [x, y, z] end