XNA旋转工作不正常

XNA旋转工作不正常,xna,rotation,Xna,Rotation,所以,我试着旋转5个向量2,得到目标(向量2)作为它们的法线。但当我旋转时,它旋转不正常。当目标指向上,垂直方向的法线向右或向左(默认值:0,-10,0,0,1)时,我必须将它们旋转90度,但当我这样做时,结果不是应该的-1,0,0 1,0。相反,它类似于:-1,vs 0,01,-vs vs=非常小的数字。为什么会这样?有没有办法纠正这个问题?代码: Vector2 target = new Vector2(0, 1); //Create target Vector2[] vecs = new

所以,我试着旋转5个向量2,得到目标(向量2)作为它们的法线。但当我旋转时,它旋转不正常。当目标指向上,垂直方向的法线向右或向左(默认值:0,-10,0,0,1)时,我必须将它们旋转90度,但当我这样做时,结果不是应该的-1,0,0 1,0。相反,它类似于:-1,vs 0,01,-vs vs=非常小的数字。为什么会这样?有没有办法纠正这个问题?代码:

Vector2 target = new Vector2(0, 1); //Create target

Vector2[] vecs = new Vector2[3] { new Vector2(0, -1), Vector2.Zero, new Vector2(0, 1) }; //Create verticies to be rotated

Matrix matrix = Matrix.CreateRotationZ(MathHelper.ToRadians(90)); //Should be: (float)Math.Atan2(target.Y, target.X) instead of 90 but wanted to simplify this

Vector2.Transform(vecs, ref matrix, vecs); // Rotate
我甚至试着360度旋转一整圈,但那没有给我起始矢量,这对我来说很奇怪。

为什么? 这是因为浮点变量的精度

有没有办法纠正这个问题? 我不知道一个方法,但我会忽略它。因为它几乎等于零

普罗蒂普
对于给定的向量(x,y),(-y,x)或(y,-x)是该向量的法线。

使用浮点运算时,预期结果0.0000001范围内的值是99.99999%的时间。