Class: Ein::Pose

Inherits:
Object
  • Object
show all
Defined in:
lib/ein/pose.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position, angle) ⇒ Pose

Returns a new instance of Pose.



11
12
13
14
# File 'lib/ein/pose.rb', line 11

def initialize(position, angle)
  @position = position
  @angle = angle
end

Instance Attribute Details

#positionObject (readonly)

Returns the value of attribute position.



9
10
11
# File 'lib/ein/pose.rb', line 9

def position
  @position
end

Instance Method Details

#advance(distance, angle) ⇒ Object

Create a new pose, modifying previous with a relative position and angle



17
18
19
20
21
22
# File 'lib/ein/pose.rb', line 17

def advance(distance, angle)
  new_angle = @angle + angle
  new_y = @position.y + distance * Math.cos(Angle.degrees_to_radians(new_angle))
  new_x = @position.x + distance * Math.sin(Angle.degrees_to_radians(new_angle))
  Pose.new(Position.new(new_x, new_y), new_angle)
end

#to_sObject



24
25
26
# File 'lib/ein/pose.rb', line 24

def to_s
  "N: #@angle, #@position"
end