Linear Mapping Example

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public static void Main()
	{
		double val = 83;
		double newVal = LinearMap(val, 0, 100, 0, 1);
		Console.WriteLine(newVal);
	}
	
	public static double LinearMap(double val, double min, double max, double newMin, double newMax) {
		return ((newMax - newMin) * (val - min) / (max - min)) + newMin;	
	}
}
;