Module: Quant::Mixins::Trig

Included in:
Filters
Defined in:
lib/quant/mixins/trig.rb

Instance Method Summary collapse

Instance Method Details

#angle(line1, line2) ⇒ Object

d = dx1*dx2 + dy1*dy2; // dot product of the 2 vectors l2 = (dx1*dx1+dy1*dy1)*(dx2*dx2+dy2*dy2) // product of the squared lengths



21
22
23
24
25
26
27
28
29
30
# File 'lib/quant/mixins/trig.rb', line 21

def angle(line1, line2)
  dx1 = line2[0][0] - line1[0][0]
  dy1 = line2[0][1] - line1[0][1]
  dx2 = line2[1][0] - line1[1][0]
  dy2 = line2[1][1] - line1[1][1]

  d = dx1 * dx2 + dy1 * dy2
  l2 = (dx1**2 + dy1**2) * (dx2**2 + dy2**2)
  rad2deg Math.acos(d / Math.sqrt(l2))
end

#deg2rad(degrees) ⇒ Object



6
7
8
# File 'lib/quant/mixins/trig.rb', line 6

def deg2rad(degrees)
  degrees * Math::PI / 180.0
end

#rad2deg(radians) ⇒ Object



10
11
12
# File 'lib/quant/mixins/trig.rb', line 10

def rad2deg(radians)
  radians * 180.0 / Math::PI
end