# 一般的な数学関数の使用

> Use Unity's Mathf class to apply trigonometric, logarithmic, and other math functions commonly required in game development.

Unity の Mathf クラスは、ゲームやアプリケーションの開発で必要とされる三角関数や対数関数など、一般的な数学関数を提供します。

このページでは、Mathf クラスの概要と、Mathf クラスを使ってスクリプトを作成する際の一般的な使用方法について説明します。Mathf クラスのすべてのメンバーの詳細なリファレンスについては、[Mathf スクリプトリファレンス](/engine/6000.0/script-reference/unity-engine/mathf.md) を参照してください。

## 三角法

Unity のすべての三角関数は、**ラジアン** で動作します。

* [`Sin`](/engine/6000.0/script-reference/unity-engine/mathf/sin.md)
* [`Cos`](/engine/6000.0/script-reference/unity-engine/mathf/cos.md)
* [`Tan`](/engine/6000.0/script-reference/unity-engine/mathf/tan.md)
* [`Asin`](/engine/6000.0/script-reference/unity-engine/mathf/asin.md)
* [`Acos`](/engine/6000.0/script-reference/unity-engine/mathf/acos.md)
* [`Atan`](/engine/6000.0/script-reference/unity-engine/mathf/atan.md)
* [`Atan2`](/engine/6000.0/script-reference/unity-engine/mathf/atan-2.md)

[`PI`](/engine/6000.0/script-reference/unity-engine/mathf/pi.md) は定数として利用でき、静的な値 [`Rad2Deg`](/engine/6000.0/script-reference/unity-engine/mathf/rad-2-deg.md) または [`Deg2Rad`](/engine/6000.0/script-reference/unity-engine/mathf/deg-2-rad.md) を掛けて、ラジアンと度の間で変換することができます。

## 累乗と平方根

Unity は、一般的な累乗と平方根の関数を提供します。

* [`Pow`](/engine/6000.0/script-reference/unity-engine/mathf/pow.md)
* [`Sqrt`](/engine/6000.0/script-reference/unity-engine/mathf/sqrt.md)
* [`Exp`](/engine/6000.0/script-reference/unity-engine/mathf/exp.md)

また、2 のべき乗関連の便利な関数もいくつか用意されています。これらは、2 のべき乗の値に制約されたり最適化されたりすることがよくある一般的なバイナリデータのサイズを扱う際に便利です (テクスチャの寸法など)。

* [`ClosestPowerOfTwo`](/engine/6000.0/script-reference/unity-engine/mathf/closest-power-of-two.md)
* [`NextPowerOfTwo`](/engine/6000.0/script-reference/unity-engine/mathf/next-power-of-two.md)
* [`IsPowerOfTwo`](/engine/6000.0/script-reference/unity-engine/mathf/is-power-of-two.md)

## 補間

Unity の補間関数を使うと、2 つの点の間にある値を計算することができます。これらの関数は、それぞれ異なる方法で動作し、異なる状況に適しています。詳細は、それぞれのページの例を参照してください。

* [`Lerp`](/engine/6000.0/script-reference/unity-engine/mathf/lerp.md)
* [`LerpAngle`](/engine/6000.0/script-reference/unity-engine/mathf/lerp-angle.md)
* [`LerpUnclamped`](/engine/6000.0/script-reference/unity-engine/mathf/lerp-unclamped.md)
* [`InverseLerp`](/engine/6000.0/script-reference/unity-engine/mathf/inverse-lerp.md)
* [`MoveTowards`](/engine/6000.0/script-reference/unity-engine/mathf/move-towards.md)
* [`MoveTowardsAngle`](/engine/6000.0/script-reference/unity-engine/mathf/move-towards-angle.md)
* [`SmoothDamp`](/engine/6000.0/script-reference/unity-engine/mathf/smooth-damp.md)
* [`SmoothDampAngle`](/engine/6000.0/script-reference/unity-engine/mathf/smooth-damp-angle.md)
* [`SmoothStep`](/engine/6000.0/script-reference/unity-engine/mathf/smooth-step.md)

[Vector クラス](/engine/6000.0/manual/scripting/object-oriented-development/vectors.md) と [`Quaternion`](/engine/6000.0/manual/scripting/object-oriented-development/class-quaternion.md) クラスには、それぞれ独自の補間関数 (Quaternion.Lerp など) があり、多次元の位置、方向、回転を補間することができます。

## 値の制限と繰り返し

これらのシンプルなヘルパー関数は、ゲームやアプリケーションで値を一定の範囲に限定したり、一定の範囲内で繰り返したりする必要がある場合に、よく使われ時間を節約することができます。

* [`Max`](/engine/6000.0/script-reference/unity-engine/mathf/max.md) と [`Min`](/engine/6000.0/script-reference/unity-engine/mathf/min.md)
* [`Repeat`](/engine/6000.0/script-reference/unity-engine/mathf/repeat.md) と [`PingPong`](/engine/6000.0/script-reference/unity-engine/mathf/ping-pong.md)
* [`Clamp`](/engine/6000.0/script-reference/unity-engine/mathf/clamp.md) と [`Clamp01`](/engine/6000.0/script-reference/unity-engine/mathf/clamp-01.md)
* [`Ceil`](/engine/6000.0/script-reference/unity-engine/mathf/ceil.md) と [`Floor`](/engine/6000.0/script-reference/unity-engine/mathf/floor.md)

## 対数

[`Log`](/engine/6000.0/script-reference/unity-engine/mathf/log.md) 関数は、指定された数値の対数を自然対数か指定した基数で計算することができます。さらに、[`Log10`](/engine/6000.0/script-reference/unity-engine/mathf/log-10.md) 関数は、指定された数値の基数 10 の対数を返します。

## その他の関数

Mathf クラスの関数のすべてのリストについては、[Mathf スクリプトリファレンス](/engine/6000.0/script-reference/unity-engine/mathf.md) を参照してください。
