Class: Roby::Pos::Vector3D
Overview
A (x, y, z) vector
Direct Known Subclasses
Instance Attribute Summary collapse
-
#x ⇒ Object
The vector coordinates.
-
#y ⇒ Object
The vector coordinates.
-
#z ⇒ Object
The vector coordinates.
Instance Method Summary collapse
-
#*(other) ⇒ Object
Returns the product of this vector with the scalar
a
. -
#+(other) ⇒ Object
Returns self + v.
-
#-(other) ⇒ Object
Returns self - v.
-
#-@ ⇒ Object
Returns the opposite of this vector.
-
#/(other) ⇒ Object
Returns the division of this vector with the scalar
a
. -
#==(other) ⇒ Object
True if
v
is the same vector thanself
. -
#distance(x = 0, y = nil, z = nil) ⇒ Object
call-seq: v.distance2d w v.distance2d x, y v.distance2d x, y, z.
-
#distance2d(x = 0, y = nil) ⇒ Object
call-seq: v.distance2d w v.distance2d x, y.
-
#initialize(x = 0, y = 0, z = 0) ⇒ Vector3D
constructor
Initializes a 3D vector.
-
#length ⇒ Object
The length of the vector.
-
#null?(tolerance = 0) ⇒ Boolean
True if this vector is of zero length.
- #pretty_print(pp) ⇒ Object
-
#to_s ⇒ Object
:nodoc:.
-
#xyz ⇒ Object
Returns the [x, y, z] array.
Constructor Details
#initialize(x = 0, y = 0, z = 0) ⇒ Vector3D
Initializes a 3D vector
11 12 13 |
# File 'lib/roby/state/pos.rb', line 11 def initialize(x = 0, y = 0, z = 0) @x, @y, @z = x, y, z end |
Instance Attribute Details
Instance Method Details
#*(other) ⇒ Object
Returns the product of this vector with the scalar a
39 40 41 |
# File 'lib/roby/state/pos.rb', line 39 def *(other) Vector3D.new(x * other, y * other, z * other) end |
#+(other) ⇒ Object
Returns self + v
29 30 31 |
# File 'lib/roby/state/pos.rb', line 29 def +(other) Vector3D.new(x + other.x, y + other.y, z + other.z) end |
#-(other) ⇒ Object
Returns self - v
34 35 36 |
# File 'lib/roby/state/pos.rb', line 34 def -(other) Vector3D.new(x - other.x, y - other.y, z - other.z) end |
#-@ ⇒ Object
Returns the opposite of this vector
49 50 51 |
# File 'lib/roby/state/pos.rb', line 49 def -@ Vector3D.new(-x, -y, -z) end |
#/(other) ⇒ Object
Returns the division of this vector with the scalar a
44 45 46 |
# File 'lib/roby/state/pos.rb', line 44 def /(other) Vector3D.new(x / other, y / other, z / other) end |
#==(other) ⇒ Object
True if v
is the same vector than self
59 60 61 62 |
# File 'lib/roby/state/pos.rb', line 59 def ==(other) other.kind_of?(Vector3D) && other.x == x && other.y == y && other.z == z end |
#distance(x = 0, y = nil, z = nil) ⇒ Object
call-seq:
v.distance2d w
v.distance2d x, y
v.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.
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/roby/state/pos.rb', line 101 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(x = 0, y = nil) ⇒ Object
call-seq:
v.distance2d w
v.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.
80 81 82 83 84 85 86 87 88 |
# File 'lib/roby/state/pos.rb', line 80 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 ⇒ Object
The length of the vector
24 25 26 |
# File 'lib/roby/state/pos.rb', line 24 def length distance(0, 0, 0) end |
#null?(tolerance = 0) ⇒ Boolean
True if this vector is of zero length. If tolerance
is non-zero, returns true if length <= tolerance.
66 67 68 |
# File 'lib/roby/state/pos.rb', line 66 def null?(tolerance = 0) length <= tolerance end |
#pretty_print(pp) ⇒ Object
19 20 21 |
# File 'lib/roby/state/pos.rb', line 19 def pretty_print(pp) pp.text to_s end |
#to_s ⇒ Object
:nodoc:
15 16 17 |
# File 'lib/roby/state/pos.rb', line 15 def to_s # :nodoc: format("Vector3D(x=%f,y=%f,z=%f)", x, y, z) end |
#xyz ⇒ Object
Returns the [x, y, z] array
54 55 56 |
# File 'lib/roby/state/pos.rb', line 54 def xyz [x, y, z] end |