facebook twitter hatena line email

「Unity/Csharp/数学」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(範囲内に)
 
(同じ利用者による、間の5版が非表示)
行10: 行10:
 
</pre>
 
</pre>
 
参考:https://kuroeveryday.blogspot.com/2015/03/Trigonometry.html
 
参考:https://kuroeveryday.blogspot.com/2015/03/Trigonometry.html
 +
 +
==整数化==
 +
切り上げ
 +
Mathf.Ceil((float)size);
 +
切り捨て
 +
Mathf.Floor((float)size);
 +
丸め(Round)
 +
Mathf.Round((float)size);
 +
 +
==大きい方を取得==
 +
Mathf.Max(1f, 2f); // 2
 +
 +
==累乗==
 +
6の二乗の場合
 +
Mathf.Pow(6, 2f));
 +
==平方根==
 +
Mathf.Sqrt(4); // 2
 +
 +
==限界値に寄せる==
 +
Debug.Log("Mathf.Clamp=" + Mathf.Clamp(5f, 0.0f, 100f)); // 5;
 +
Debug.Log("Mathf.Clamp=" + Mathf.Clamp(101f, 0.0f, 100f)); // 100;
 +
Debug.Log("Mathf.Clamp=" + Mathf.Clamp(-1f, 0.0f, 100f)); // 0;
 +
 +
==値を範囲内に==
 +
150を100で割ったあまりを計算
 +
Mathf.Repeat(150, 100));

2022年12月6日 (火) 11:47時点における最新版

小数点第二位まで

float num = 1.1234f;
num.ToString("f2");

角度

int angle = 10; // 10度の場合
double x = Math.Sin(angle * (Math.PI / 180));
double y = Math.Cos(angle * (Math.PI / 180));

参考:https://kuroeveryday.blogspot.com/2015/03/Trigonometry.html

整数化

切り上げ

Mathf.Ceil((float)size);

切り捨て

Mathf.Floor((float)size);

丸め(Round)

Mathf.Round((float)size);

大きい方を取得

Mathf.Max(1f, 2f); // 2

累乗

6の二乗の場合

Mathf.Pow(6, 2f));

平方根

Mathf.Sqrt(4); // 2

限界値に寄せる

Debug.Log("Mathf.Clamp=" + Mathf.Clamp(5f, 0.0f, 100f)); // 5;
Debug.Log("Mathf.Clamp=" + Mathf.Clamp(101f, 0.0f, 100f)); // 100;
Debug.Log("Mathf.Clamp=" + Mathf.Clamp(-1f, 0.0f, 100f)); // 0;

値を範囲内に

150を100で割ったあまりを計算

Mathf.Repeat(150, 100));