Class: TerminalVis::Interpolation::LinearInterpolation

Inherits:
Object
  • Object
show all
Defined in:
lib/math/linear_interpolation.rb

Overview

math class to apply linear interpolation between two points

Class Method Summary collapse

Class Method Details

.linear_interpolation(data_point0, data_point1, x, y) ⇒ Object

singleton method for linear interpolation between two points

Parameters:

  • data_point0 (DataPoint)

    first datapoint

  • data_point1 (DataPoint)

    second datapoint

  • x (Float)

    x-coordinate of the interpolation point

  • y (Float)

    y-coordinate of the interpolation point



18
19
20
21
22
# File 'lib/math/linear_interpolation.rb', line 18

def self.linear_interpolation(data_point0, data_point1, x, y)
  r = Interpolation::calculate_interpolation_factor(data_point0,
                                                    data_point1, x, y)
  ((1-r) * data_point0.value + r * data_point1.value).round(3)
end