0
我遵循this文章中介紹的用於在WPF中顯示散點圖數據的文章。我可以很容易地旋轉視圖矩陣中的圖像,但我需要旋轉原始數據點,並將z軸值的最小二乘擬合擬合到z = 0平面。我只需要旋轉數據5-20度,所以我不認爲我需要四元數來避免靈活的鎖定。我已經嘗試了以下方法,並嘗試在旋轉之前將數據轉換爲原點,但未按預期工作。 RotateX方法似乎可行,但其他兩種方法似乎將所有數據一起壓縮在y軸或z軸上。我檢查了大約10個不同網站的公式,並且找不到任何錯誤,但結果仍然沒有意義。在WPF中旋轉3D散點圖數據不能按預期方式工作
public static Point3D RotateAboutX(Point3D pt1, double aX)
{
double angleX = 3.1415926 * aX/180;
double x2 = pt1.X;
double y2 = (pt1.Y * Math.Cos(angleX)) - (pt1.Z * Math.Sin(angleX));
double z2 = (pt1.Y * Math.Sin(angleX)) + (pt1.Z * Math.Cos(angleX));
return new Point3D(x2, y2, z2);
}
public static Point3D RotateAboutY(Point3D pt1, double aY)
{
double angleY = 3.1415926 * aY/180;
double x2 = (pt1.X * Math.Cos(angleY)) - (pt1.Z * Math.Sin(angleY));
double y2 = pt1.Y;
double z2 = (pt1.X * Math.Sin(angleY)) + (pt1.Z * Math.Cos(angleY));
return new Point3D(x2, y2, z2);
}
public static Point3D RotateAboutZ(Point3D pt1, double aZ)
{
double angleZ = 3.1415926 * aZ/180;
double x2 = (pt1.X * Math.Cos(angleZ)) - (pt1.Y * Math.Sin(angleZ));
double y2 = (pt1.X * Math.Sin(angleZ)) + (pt1.Y * Math.Cos(angleZ));
double z2 = pt1.Z;
return new Point3D(x2, y2, z2);
}