Here you can find the source of interpolate(float t, float a, float b)
Parameter | Description |
---|---|
t | when 0, the result is a, when 1, the result is b. |
a | value at start of range |
b | value at end of range |
public static float interpolate(float t, float a, float b)
//package com.java2s; /*/*from w ww. j a v a 2 s .c o m*/ * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2007-2008, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ public class Main { /** * Does a linear interpolation. * * @param t when 0, the result is a, when 1, the result is b. * @param a value at start of range * @param b value at end of range * * @return an interpolated value between a and b (or beyond), with the relative position t. */ public static float interpolate(float t, float a, float b) { return a + t * (b - a); } /** * Does a linear interpolation using doubles * * @param t when 0, the result is a, when 1, the result is b. * @param a value at start of range * @param b value at end of range * * @return an interpolated value between a and b (or beyond), with the relative position t. */ public static double interpolate(double t, double a, double b) { return a + t * (b - a); } /** * Calculates a linearily interpolated value, given a start value and position, an end value and position, * and the position to get the value at. * <p/> * First calculates the relative position, then does a normal linear interpolation between the start and end value, * using the relative position as the interpolation factor. * * @param position * @param startPosition * @param endPosition * @param startValue * @param endValue * * @return the interpolated value */ public static double interpolate(final double position, final double startPosition, final double endPosition, final double startValue, final double endValue) { final double relativePosition = (position - startPosition) / (endPosition - startPosition); return startValue + relativePosition * (endValue - startValue); } }