Mathfクラス
5619 ワード
Mathf類はまだ比較的多いものがありますが、今日は時間をかけて見て、以下のように記録しました.
注意:3つの異なる運動があります
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//Mathf
public class MathfTest : MonoBehaviour {
//// Use this for initialization
void Start()
{
//
Debug.Log(" :" + Mathf.Deg2Rad);
Debug.Log(" :" + Mathf.Rad2Deg);
Debug.Log(" :" + Mathf.PI);
Debug.Log(" ( ):" + Mathf.Epsilon);
Debug.Log(" ( ):" + Mathf.Infinity);
Debug.Log(" ( )" + Mathf.NegativeInfinity);
//
Debug.Log(" , 0 1, -1:"+Mathf.Sign(-10)+":::"+Mathf.Sign(10));
Debug.Log(" :" + Mathf.Abs(-10)); //print 10
Debug.Log(" (float ):"+Mathf.Round(10.5f)+":::"+Mathf.Round(10.6f));
Debug.Log(" (int ):" + Mathf.RoundToInt(-10.5f) + ":::" + Mathf.RoundToInt(-10.6f));
Debug.Log(" :" + Mathf.Approximately(2.0f, 5.0f)); //print true/false
Debug.Log(" ( float ):" + Mathf.Ceil(0.6f));
Debug.Log(" ( int ):" + Mathf.CeilToInt(5.3f));
Debug.Log(" ( float ):" + Mathf.Floor(0.6f));
Debug.Log(" ( int ):" + Mathf.FloorToInt(1.6f));
Debug.Log(" :" + Mathf.Clamp(5, 10, 12)); //
Debug.Log(" 01:" + Mathf.Clamp01(0.5f)); // 0-1
Debug.Log(" value 2 。:" + Mathf.ClosestPowerOfTwo(5)); // 4
Debug.Log(" 2 N :"+Mathf.IsPowerOfTwo(8)); // true/false
Debug.Log(" 2 N :"+Mathf.NextPowerOfTwo(129));
Debug.Log(" :" + Mathf.DeltaAngle(1080, 90)); //1080 0 90-0 = 90
//
Debug.Log(" a b :"+Mathf.Pow(6f, 2f));
Debug.Log(" :" + Mathf.Sqrt(4));
Debug.Log("e N :" + Mathf.Exp(6)); //e: e( 2.71828)
Debug.Log(" :" + Mathf.Log(6, 2)); // 6 ,2
Debug.Log(" ( ):" + Mathf.Log(6)); // , e
Debug.Log(" 10 :" + Mathf.Log10(100));
// ( )
Debug.Log(" ( c ab ):" + Mathf.InverseLerp(2f, 8f, 5f)); //5 2 8 0.5
Debug.Log(" ( c ab ):"+Mathf.Lerp(1f,10f,0.8f)); //print 8.2 (10-1)*0.8 = 7.2+1 = 8.2
Debug.Log(" :" + Mathf.LerpAngle(0.0f,90.0f,0.5f)); /// 45
Debug.Log(" a b , t , ab :" + Mathf.LerpUnclamped(0.5f, 9.0f, 1.6f));
//
Debug.Log(" :" + Mathf.MoveTowards(1.0f, 10.0f, 2.0f)); // 1+2=3
Debug.Log(" :"+Mathf.MoveTowardsAngle(30.0f,90.0f,10.0f));
//
Debug.Log(" a "+Mathf.PingPong(1.0f,10.0f)); // t 1-10 ( update )
Debug.Log(" " + Mathf.Repeat(1.0f, 5.0f)); // 1-5 Mathf.PingPong
//Perlin Noise : x,y , , Random , , 。 , x y , 。
Debug.Log(" "+Mathf.PerlinNoise(0.5f,0.5f));
// ( int&float ),
Debug.Log(" :"+Mathf.Max(2.0f,3.6f));
int[] i = { 5,9,6,3,45,8,};
Debug.Log(" :" + Mathf.Max(i));
Debug.Log(" :" + Mathf.Min(2.0f, 3.6f));
int[] ii = { 5, 9, 6, 3, 45, 8, };
Debug.Log(" :" + Mathf.Min(ii));
//
Debug.Log(" : lerp , , " + Mathf.SmoothStep(1.0f,10.0f,2.0f));
//
//Debug.Log(" :"+ Mathf.SmoothDampAngle(current: float, target: float, ref currentVelocity : float, smoothTime: float, maxSpeed: float = Mathf.Infinity, deltaTime: float = Time.deltaTime));
// : 。
//Mathf.SmoothDamp(current: float, target: float, ref currentVelocity : float, smoothTime: float, maxSpeed: float = Mathf.Infinity, deltaTime: float = Time.deltaTime)
//Unity5.6 , RGB
//print(Mathf.CorrelatedColorTemperatureToRGB(float kelvin)) kelvin 1000-40000
//5.6 (sRGB) 。
//Mathf.GammaToLinearSpace(float value);
//5.6 (sRGB) 。
//Mathf.LinearToGammaSpace(float value);
// , ,
// 2
print(Mathf.Acos(1f));
print(Mathf.Asin(1f));
print(Mathf.Atan(1f));
print(Mathf.Atan2(1f, 2f));
// , Mathf
print(Mathf.Cos(0.5f));
print(Mathf.Sin(Mathf.Deg2Rad * 30)); // sin(30) 0.5
print(Mathf.Tan(0.5f));
}
// Update is called once per frame
void Update () {
}
}
注意:3つの異なる運動があります
// ( )
Debug.Log(" ( c ab ):" + Mathf.InverseLerp(2f, 8f, 5f)); //5 2 8 0.5
Debug.Log(" ( c ab ):"+Mathf.Lerp(1f,10f,0.8f)); //print 8.2 (10-1)*0.8 = 7.2+1 = 8.2
Debug.Log(" :" + Mathf.LerpAngle(0.0f,90.0f,0.5f)); /// 45
Debug.Log(" a b , t , ab :" + Mathf.LerpUnclamped(0.5f, 9.0f, 1.6f));
//
Debug.Log(" :" + Mathf.MoveTowards(1.0f, 10.0f, 2.0f)); // 1+2=3
Debug.Log(" :"+Mathf.MoveTowardsAngle(30.0f,90.0f,10.0f));
//
Debug.Log(" a "+Mathf.PingPong(1.0f,10.0f)); // t 1-10 ( update )
Debug.Log(" " + Mathf.Repeat(1.0f, 5.0f)); // 1-5 Mathf.PingPong