Method: Mittsu::Spline#point

Defined in:
lib/mittsu/math/spline.rb

#point(k) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mittsu/math/spline.rb', line 22

def point(k)
  point = (@points.length - 1) * k
  int_point = point.floor
  weight = point - int_point

  @c[0] = int_point.zero? ? int_point : int_point - 1
  @c[1] = int_point
  @c[2] = int_point > @points.length - 1 ? @points.length - 1 : int_point + 1
  @c[3] = int_point > @points.length - 3 ? @points.length - 1 : int_point + 2

  pa = @points[c[0]]
  pb = @points[c[1]]
  pc = @points[c[2]]
  pd = @points[c[3]]

  w2 = weight * weight
  w3 = weight * w2

  v3.x = interpolate(pa.x, pb.x, pc.x, pd.x, weight, w2, w3)
  v3.y = interpolate(pa.y, pb.y, pc.y, pd.y, weight, w2, w3)
  v3.z = interpolate(pa.z, pb.z, pc.z, pd.z, weight, w2, w3)

  v3
end