There Useful Methods By Bit-101

package com.bit101.utils
{
	public class NumberUtils
	{
		public static function normalize(value:Number, minimum:Number, maximum:Number):Number
		{
			return (value - minimum) / (maximum - minimum);
		}
		public static function interpolate(normValue:Number, minimum:Number, maximum:Number):Number
		{
			return minimum + (maximum - minimum) * normValue;
		}
		public static function map(value:Number, min1:Number, max1:Number, min2:Number, max2:Number):Number
		{
			return interpolate( normalize(value, min1, max1), min2, max2);
		}
	}
}

在算一些相对比例的时候(比如做滚动条),这三个方法很常用。虽然是很简单的数学知识,但是还是记录下来免得突然有时脑筋打结。

normalize() // 计算比例,正常范围是在0~1之间

interpolate() // 根据比例、最大最小值算出对应值

map() // 根据四个极值算出对应值

Comments :

Author (Required)
Email (Required, not published)
URL

Related Posts :


Warning: unserialize() expects parameter 1 to be string, array given in /home/.mercury/kvc/kevincao.com/wp-content/plugins/wheredidtheygov1.php on line 97

Readers who viewed this page, also viewed :

  • N/A
Close
E-mail It
Socialized through Gregarious 42