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

提供: 初心者エンジニアの簡易メモ
ナビゲーションに移動 検索に移動
18行目: 18行目:
丸め(Round)
丸め(Round)
  Mathf.Round((float)size);
  Mathf.Round((float)size);
==大きい方を取得==
Mathf.Max(1f, 2f); // 2

2021年10月29日 (金) 17:08時点における版

小数点第二位まで

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