我正在Unity中使用该功能
Quaternion.LookRotation(normal, (0,1,0));
您可以在https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html找到文档。如果法线平行于y轴,则应该是一个问题。由于无法创建由函数创建的坐标系,因此生成的四元数的方向围绕y轴旋转因此,我尝试使用
覆盖这种边缘情况if(Vector3.Angle(normal, new Vector3(0, 1, 0)==0) ||Vector3.Angle(normal, new Vector3(0, 1, 0)==180) )
[调试后,我意识到问题是每个Vector3.Angle(正常,新的Vector3(0,1,0)在170到180之间出现问题。我需要获得一个非常精确的方向,所以我的问题是你知道为什么吗这种不准确性正在发生,并且如何正确处理。谢谢!
Quaternion rot =
Mathf.Abs(Vector3.Dot(normal.normalized,Vector3.up))<0.99f
? Quaternion.LookRotation( normal , Vector3.up )
: Quaternion.identity;