Class: TPoint
- Inherits:
-
Object
- Object
- TPoint
- Includes:
- Propane::Proxy
- Defined in:
- lib/math_demo/triangle_point.rb
Overview
particle and triangle point
Instance Attribute Summary collapse
-
#accel ⇒ Object
readonly
Returns the value of attribute accel.
-
#bounds ⇒ Object
readonly
Returns the value of attribute bounds.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
-
#vel ⇒ Object
readonly
Returns the value of attribute vel.
Instance Method Summary collapse
- #direction(acc) ⇒ Object
-
#initialize(position) ⇒ TPoint
constructor
attr_reader :width, :height # uncomment for testing.
- #update ⇒ Object
Constructor Details
Instance Attribute Details
#accel ⇒ Object (readonly)
Returns the value of attribute accel.
5 6 7 |
# File 'lib/math_demo/triangle_point.rb', line 5 def accel @accel end |
#bounds ⇒ Object (readonly)
Returns the value of attribute bounds.
5 6 7 |
# File 'lib/math_demo/triangle_point.rb', line 5 def bounds @bounds end |
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
5 6 7 |
# File 'lib/math_demo/triangle_point.rb', line 5 def pos @pos end |
#vel ⇒ Object (readonly)
Returns the value of attribute vel.
5 6 7 |
# File 'lib/math_demo/triangle_point.rb', line 5 def vel @vel end |
Instance Method Details
#direction(acc) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/math_demo/triangle_point.rb', line 15 def direction(acc) # direction of the acceleration is defined by the new angle @accel = acc # magnitude of the acceleration is proportional to the angle between # acceleration and velocity dif = acc.angle_between(vel) dif = map1d(dif, 0..PI, 0.1..0.001) @accel = acc * dif end |
#update ⇒ Object
25 26 27 28 29 30 |
# File 'lib/math_demo/triangle_point.rb', line 25 def update @vel += accel @vel.set_mag(1.5) { vel.mag > 1.5 } @pos += vel check_bounds end |