Here you can find the source of interpolateLinear(int[] vec, int start, int end)
Parameter | Description |
---|---|
vec | The array that gives number of values. |
start | The start value for the linear interpolation. |
end | The end value for the linear interpolation. |
public static int[] interpolateLinear(int[] vec, int start, int end)
//package com.java2s; //License from project: Open Source License public class Main { /**/* ww w. j a va 2s. c om*/ * Given an array of integers, compute a series of integers as a linear * interpolation between two values. * * @param vec * The array that gives number of values. * @param start * The start value for the linear interpolation. * @param end * The end value for the linear interpolation. * @return A new array containing the interpolated values. */ public static int[] interpolateLinear(int[] vec, int start, int end) { double step; int length = vec.length; int ret[] = new int[vec.length]; if (start < end) { step = (double) (end - start) / (double) length; for (int i = 0; i < length; i++) { if (vec[i] != 0) { ret[i] = start + (int) (i * step); } } } else if (start > end) { step = (double) (start - end) / (double) length; for (int i = 0; i < length; i++) if (vec[i] != 0) ret[i] = start - (int) (i * step); } else for (int i = 0; i < length; i++) if (vec[i] != 0) ret[i] = start; return ret; } }