Module: ClimbFactor::CfMath

Defined in:
lib/climb_factor/low_level_math.rb

Class Method Summary collapse

Class Method Details

.add2d(p, q) ⇒ Object



31
32
33
# File 'lib/climb_factor/low_level_math.rb', line 31

def self.add2d(p,q)
  return [p[0]+q[0],p[1]+q[1]]
end

.deg_to_rad(x) ⇒ Object



3
4
5
# File 'lib/climb_factor/low_level_math.rb', line 3

def self.deg_to_rad(x)
  return 0.0174532925199433*x
end

.dist2d(p, q) ⇒ Object



51
52
53
# File 'lib/climb_factor/low_level_math.rb', line 51

def self.dist2d(p,q)
  return mag2d(sub2d(p,q))
end

.dot2d(p, q) ⇒ Object



39
40
41
# File 'lib/climb_factor/low_level_math.rb', line 39

def self.dot2d(p,q)
  return p[0]*q[0]+p[1]*q[1]
end

.interpolate_square(x, y, z00, z10, z01, z11) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/climb_factor/low_level_math.rb', line 15

def self.interpolate_square(x,y,z00,z10,z01,z11)
  # https://en.wikipedia.org/wiki/BiClimbFactorMath.linear_interpolation#Unit_Square
  # The crucial thing is that this give results that are continuous across boundaries of squares.
  w00 = (1.0-x)*(1.0-y)
  w10 = x*(1.0-y)
  w01 = (1.0-x)*y
  w11 = x*y
  norm = w00+w10+w01+w11
  z = (z00*w00+z10*w10+z01*w01+z11*w11)/norm
  return z
end

.linear_interp(x1, x2, s) ⇒ Object



27
28
29
# File 'lib/climb_factor/low_level_math.rb', line 27

def self.linear_interp(x1,x2,s)
  return x1+s*(x2-x1)
end

.mag2d(p) ⇒ Object



55
56
57
# File 'lib/climb_factor/low_level_math.rb', line 55

def self.mag2d(p)
  return Math::sqrt(dot2d(p,p))
end

.normalize2d(p) ⇒ Object



47
48
49
# File 'lib/climb_factor/low_level_math.rb', line 47

def self.normalize2d(p)
  return scalar_mul2d(p,1.0/mag2d(p))
end

.pythag(x, y) ⇒ Object



11
12
13
# File 'lib/climb_factor/low_level_math.rb', line 11

def self.pythag(x,y)
  return Math::sqrt(x*x+y*y)
end

.rad_to_deg(x) ⇒ Object



7
8
9
# File 'lib/climb_factor/low_level_math.rb', line 7

def self.rad_to_deg(x)
  return x/0.0174532925199433
end

.scalar_mul2d(p, s) ⇒ Object



43
44
45
# File 'lib/climb_factor/low_level_math.rb', line 43

def self.scalar_mul2d(p,s)
  return [s*p[0],s*p[1]]
end

.sub2d(p, q) ⇒ Object



35
36
37
# File 'lib/climb_factor/low_level_math.rb', line 35

def self.sub2d(p,q)
  return [p[0]-q[0],p[1]-q[1]]
end