Java examples for java.lang:Math Algorithm
Performs a Catmull-Rom interpolation using the specified positions.
//package com.java2s; public class Main { /**/*from www . j a va 2 s.co m*/ * Performs a Catmull-Rom interpolation using the specified positions. * * @param value1 * The first position in the interpolation. * @param value2 * The second position in the interpolation. * @param value3 * The third position in the interpolation. * @param value4 * The fourth position in the interpolation. * @param amount * Weighting factor. * @return A position that is the result of the Catmull-Rom interpolation. */ public static float catmullRom(float value1, float value2, float value3, float value4, float amount) { // Using formula from http://www.mvps.org/directx/articles/catmull/ // Internally using doubles not to lose precission double amountSquared = amount * amount; double amountCubed = amountSquared * amount; return (float) (0.5 * (2.0 * value2 + (value3 - value1) * amount + (2.0 * value1 - 5.0 * value2 + 4.0 * value3 - value4) * amountSquared + (3.0 * value2 - value1 - 3.0 * value3 + value4) * amountCubed)); } }