我尝试使用 .NET 中的 System.Numerics 库围绕轴 (Y) (0,1,0) 以特定角度 (90°) 旋转矢量 (0,0,-1)
我的问题是我得到了错误的输出,我没有得到问题所在。代码的输出是:原始向量:<0 0 -1> 旋转向量:<-0,99999994 0 -5,9604645E-08>
如果我将矢量 (0,0,-1) 绕 (0,1,0) 旋转 990 度,则输出应为(-1,0,0)
using System.Numerics;
class Program
{
static void Main()
{
Vector3 vector = new Vector3(0,0,-1);
Vector3 rotateAxis = new Vector3(0,1,0);
float angle = 90;
//Create Radians
float radians = (float)(angle *Math.PI/180);
Quaternion rotation = Quaternion.CreateFromAxisAngle(rotateAxis, radians);
// Rotate Vector
Vector3 rotatedVector = Vector3.Transform(vector,rotation);
Console.WriteLine($"Original vector: {vector}");
Console.WriteLine($"rotated vector: {rotatedVector}");
}
}