Class: TPoint

Inherits:
Object
  • Object
show all
Includes:
Propane::Proxy
Defined in:
lib/math_demo/triangle_point.rb

Overview

particle and triangle point

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#accelObject (readonly)

Returns the value of attribute accel.



5
6
7
# File 'lib/math_demo/triangle_point.rb', line 5

def accel
  @accel
end

#posObject (readonly)

Returns the value of attribute pos.



5
6
7
# File 'lib/math_demo/triangle_point.rb', line 5

def pos
  @pos
end

#velObject (readonly)

Returns the value of attribute vel.



5
6
7
# File 'lib/math_demo/triangle_point.rb', line 5

def vel
  @vel
end

#xboundObject (readonly)

Returns the value of attribute xbound.



5
6
7
# File 'lib/math_demo/triangle_point.rb', line 5

def xbound
  @xbound
end

#yboundObject (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

#updateObject



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