CSharp examples for System:Math Number
Linear interpolation.
/*//from w ww. j a va 2 s .c o m * Copyright (C) 2011 - 2013 Voxeliq Engine - http://www.voxeliq.org - https://github.com/raistlinthewiz/voxeliq * * This program is free software; you can redistribute it and/or modify * it under the terms of the Microsoft Public License (Ms-PL). */ using System; public class Main{ /// <summary> /// Linear interpolation. /// </summary> /// <param name="x1"></param> /// <param name="x2"></param> /// <param name="p"></param> /// <returns></returns> public static double Lerp(double x1, double x2, double p) { return x1 * (1.0 - p) + x2 * p; } /// <summary> /// Linear interpolation. /// </summary> /// <param name="x"></param> /// <param name="x1"></param> /// <param name="x2"></param> /// <param name="q00"></param> /// <param name="q01"></param> /// <returns></returns> public static double Lerp(double x, double x1, double x2, double q00, double q01) { return ((x2 - x) / (x2 - x1)) * q00 + ((x - x1) / (x2 - x1)) * q01; } }