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
# File 'lib/math_demo/triangle_point.rb', line 8

def initialize(position)
  @pos = position
  @vel = Vec2D.new
  @accel = Vec2D.random
  @bounds = [Boundary.new(0, width), 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

#boundsObject (readonly)

Returns the value of attribute bounds.



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

def bounds
  @bounds
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

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

#updateObject



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