0
0

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 3 years have passed since last update.

C# Mathf

Posted at

##0.0 はじめに
数関係の処理に便利なMathfをいくつかまとめてみました。

##1.0 関数

####1.1 小数点四捨五入等

関数 説明 使用例
Floor() 切り捨て Mathf.Floor(1.5f) // = 1
Ceil() 切り上げ Mathf.Ceil(1.5f) // = 2
Round() 四捨五入 Mathf.Round(1.5f) // = 2

####1.2 比較や判定

関数 説明 使用例
Sign() 符号取得 (0の場合は1) Mathf.Sign(-1.5f) // = -1 (= マイナス)
Min() 最小数を返す Mathf.Min(1.5f, 1.7f) // = 1.5
Max() 最大数を返す Mathf.Max(1.5f, 1.7f, 1.9f, 2.5f) // = 2.5

####1.3 特殊計算

関数 説明 使用例
Pow() 指数 Mathf.Pow(2, 3) // 2の3乗=8
Sqrt() 平方根 Mathf.Sqrt(4) // √4 = 2
Abs() 絶対値 Mathf.Abs(-1.5f) // = 1.5

####1.4 範囲指定

関数 説明 使用例
Clamp() 上下限を指定 Mathf.Clamp(-10, 0, 50); // 0
Clamp01() 値を0 と 1 の間に制限 Mathf.Clamp01(1.5f); // 1
Lerp() 線形補完 第三引数は0~1f Mathf.Lerp(0.5f, 4.5f, 0.75f); // 0.5と4.5の間75%=3.5

👍ポイント
ベクトルVector3にも同様に線形補完用Lerp()関数があります。(Vector3.Lerp():ベクトルでの線形補完)

##2.0 定数

定数 説明
PI π (3.1415926...)
Deg2Rad 度からラジアンに変換する定数
Rad2Deg ラジアンから度に変換する定数
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?