1.本文的应用背景在比如要去解决一个动态转身的问题
2.已知两个向量如何求解夹角?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MathTool : MonoBehaviour {
public static float getAngl(Vector3 vec1, Vector3 vec2)
{
float sita = dot(vec1, vec2) / (module(vec1) * module(vec2));
float angel = Mathf.Acos(sita);
angel = angel * Mathf.Rad2Deg;
Debug.Log(angel);
return angel;
}
void Update()
{
if(Input.GetKeyDown(KeyCode.S))
{
Debug.Log(getAngl(new Vector3(1,0,0),new Vector3(0.5f,0.5f,0)));
}
}
/// <summary>
/// 返回两个向量的点乘结果
/// </summary>
/// <returns></returns>
public static float dot(Vector3 vec1, Vector3 vec2)
{
return vec1.x * vec2.x + vec1.y * vec2.y + vec1.z * vec2.z;
}
public static float module(Vector3 vec1)
{
return Mathf.Sqrt(vec1.x * vec1.x + vec1.y * vec1.y + vec1.z * vec1.z);
}
}