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.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
-
#vel ⇒ Object
readonly
Returns the value of attribute vel.
-
#xbound ⇒ Object
readonly
Returns the value of attribute xbound.
-
#ybound ⇒ Object
readonly
Returns the value of attribute ybound.
Instance Method Summary collapse
- #direction(acc) ⇒ Object
-
#initialize(position) ⇒ TPoint
constructor
attr_reader :width, :height # uncomment for testing.
- #update ⇒ Object
Constructor Details
#initialize(position) ⇒ TPoint
attr_reader :width, :height # uncomment for testing
8 9 10 11 12 13 14 |
# File 'lib/math_demo/triangle_point.rb', line 8 def initialize(position) @pos = position @vel = Vec2D.new @accel = Vec2D.random @xbound = Boundary.new(0, width) @ybound = Boundary.new(0, height) end |
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 |
#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 |
#xbound ⇒ Object (readonly)
Returns the value of attribute xbound.
5 6 7 |
# File 'lib/math_demo/triangle_point.rb', line 5 def xbound @xbound end |
#ybound ⇒ Object (readonly)
Returns the value of attribute ybound.
5 6 7 |
# File 'lib/math_demo/triangle_point.rb', line 5 def ybound @ybound end |
Instance Method Details
#direction(acc) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/math_demo/triangle_point.rb', line 16 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
26 27 28 29 30 31 |
# File 'lib/math_demo/triangle_point.rb', line 26 def update @vel += accel @vel.set_mag(1.5) { vel.mag > 1.5 } @pos += vel check_bounds end |