Module: TerminalVis::Interpolation

Defined in:
lib/math/interpolation.rb,
lib/math/linear_interpolation.rb,
lib/math/region_interpolation.rb,
lib/math/bilinear_interpolation.rb

Overview

This module holds methods and classes to interpolate data values with different methods. The following interpolation methods are implemented:

* Linear interpolation
* Bilinear interpolation
* Region interpolation

Defined Under Namespace

Classes: BilinearInterpolation, DataPoint, LinearInterpolation, RegionInterpolation

Class Method Summary collapse

Class Method Details

.calculate_interpolation_factor(data_point0, data_point1, x, y) ⇒ Float

singleton method to calculate interpolation coefficient with accuracy to the fifth digit

Parameters:

  • data_point0 (DataPoint)

    DataPoint with coordinates and value needed for the interpolation

  • data_point1 (DataPoint)

    DataPoint with coordinates and value needed for the interpolation

  • x (Float)

    x-coordinate of the interpolation point

  • y (Float)

    y-coordinate of the interpolation point

Returns:

  • (Float)

    the calculated interpolation factor rounded to the fifth digit



70
71
72
73
74
75
76
# File 'lib/math/interpolation.rb', line 70

def self.calculate_interpolation_factor(data_point0, data_point1, x, y)
  coordinate = DataPoint.new(x, y)
  ( (coordinate.coordinate - data_point0.coordinate).
    dot(data_point1.coordinate - data_point0.coordinate) /
    (data_point1.coordinate - data_point0.coordinate).magnitude**2).
  round(5)
end

.interpolate_for_coordinate(meta_data, coordinates, data_set) ⇒ Float

interpolates the data for the provided coordinate and prints the result

Parameters:

  • meta_data (VisMetaData)

    the meta data for the data series where the interpolation should be done

  • coordinates (Hash)

    the coordinates for the interpolation

  • data_set (DataSet)

    the dataset where the interpolation shall be applied on

Returns:

  • (Float)

    the interpolated value for the given input



26
27
28
29
30
31
32
33
# File 'lib/math/interpolation.rb', line 26

def self.interpolate_for_coordinate(, coordinates, data_set)

  x_coordinate = coordinates[:x]
  y_coordinate = coordinates[:y]

  BilinearInterpolation.bilinear_interpolation(, data_set,
                                               x_coordinate, y_coordinate)
end

.linear_interpolation_for_coordinate(data_point0, data_point1, x, y) ⇒ Float

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

Returns:

  • (Float)

    the interpolated value for the given input



41
42
43
# File 'lib/math/interpolation.rb', line 41

def self.linear_interpolation_for_coordinate(data_point0, data_point1, x, y)
  LinearInterpolation.linear_interpolation(data_point0, data_point1, x, y)
end

.region_interpolation(meta_data, data_set, coordinates, values) ⇒ Object

singleton method to interpolate the data values specified for the region defined by the coordinates and the interval and delta values

Parameters:

  • meta_data (VisMetaData)

    the meta data of the considered data set

  • data_set (DataSet)

    the data_set which values are taken to interpolate the region

  • coordinates (Hash)

    a hash containing the x- and y-coordinate

  • values (Hash)

    a hash containing all relevant values for the region interpolation



53
54
55
56
57
58
# File 'lib/math/interpolation.rb', line 53

def self.region_interpolation(, data_set, coordinates, values)
  ri = RegionInterpolation.new(values[:inter_x], values[:delta_x],
                               values[:inter_y], values[:delta_y])
  ri.interpolate_region(coordinates[:x], coordinates[:y],
                                 , data_set)
end