Class: Ein::Pose
- Inherits:
-
Object
- Object
- Ein::Pose
- Defined in:
- lib/ein/pose.rb
Instance Attribute Summary collapse
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Instance Method Summary collapse
-
#advance(distance, angle) ⇒ Object
Create a new pose, modifying previous with a relative position and angle.
-
#initialize(position, angle) ⇒ Pose
constructor
A new instance of Pose.
- #to_s ⇒ Object
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
#position ⇒ Object (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_s ⇒ Object
24 25 26 |
# File 'lib/ein/pose.rb', line 24 def to_s "N: #@angle, #@position" end |