Interpolation was a need for several reason. Here we show to you simple interpolation class by using linear interpolation.
public class Interpolate { // Value1 ValueNeed Value2 // // Value3 Result1 Value4 public double Interpolate1(double Value1, double Value2, double Value3, double Value4, double ValueNeed) { double Result1 = ((ValueNeed - Value1) * (Value4 - Value3) / (Value2 - Value1)) + Value3; return Result1; } // Value1 Value2 // // ValueNeed Result1 // // Value3 Value4 public double Interpolate2(double Value1, double Value2, double Value3, double Value4, double ValueNeed) { double Result1 = ((ValueNeed - Value1) * (Value4 - Value2) / (Value3 - Value1)) + Value2; return Result1; } // Value1 ValueNeed Value2 // // ValueNeed2 Result4 // // Value3 Result3 Value4 public double Interpolate3(double Value1, double Value2, double Value3, double Value4, double ValueNeed, double ValueNeed2) { double Result3 = ((ValueNeed - Value1) * (Value4 - Value3) / (Value2 - Value1)) + Value3; double Result4 = ((ValueNeed2 - Value1) * (Result3 - ValueNeed) / (Value3 - Value1)) + ValueNeed; return Result4; } }
Description
- The above coding used for simple linear interpolation.
- There are three option of interpolation available here which is base on the position of interpolation you need. This interpolation also can be used to interpolate from table.
- Method to used it, just create class for this interpolation and call it !!