4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

remap関数の汎用性は異常

Last updated at Posted at 2012-10-10
static double remap(double value, double inputMin, double inputMax, double outputMin, double outputMax)
{
    return (value - inputMin) * ((outputMax - outputMin) / (inputMax - inputMin)) + outputMin;
}

コピペで使えます。
例えば

for(int i = 0 ; i < 100 ; ++i)
{
    double t = remap(i, 0, 99, 0, 1); // t は 0 -> 1 を線形にイテレーションする 
}

とか、UISliderの0~1の値を 100~50 にするのなんかもすごくスッキリ書けます

staticつけて内部結合にして使うもよし、
つけないで外部結合にして使い回すのもよし。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?