简体   繁体   English

在WPF中旋转3D散点图数据无法正常工作

[英]Rotating 3D scatter plot data in WPF not working as expected

I have followed the model presented in this article for displaying scatter plot data in WPF. 我已按照提出的模型文章在WPF显示散点图数据。 I can easily rotate the image in the view matrix but I need to rotate the raw data points and do a least squares fit of the z-axis values to the z=0 plane. 我可以轻松地在视图矩阵中旋转图像,但是我需要旋转原始数据点,并对z轴值与z = 0平面进行最小二乘拟合。 I only need to rotate the data 5-20 degrees so I don't think I need quaternions to avoid gimble lock. 我只需要将数据旋转5-20度,这样我就不需要四元数来避免万向节锁定。 I have tried the following methods and have also tried translating the data to the origin before rotating but it has not worked as expected. 我尝试了以下方法,还尝试了在旋转之前将数据转换为原点,但未按预期工作。 The RotateX method seems to work but the other 2 methods seem to squish all the data together either in the y axis or the z axis. RotateX方法似乎可以工作,但是其他两种方法似乎可以将所有数据沿y轴或z轴压缩在一起。 I've checked the formulas with about 10 different sites and can't find any errors but the results still don't make sense. 我已经在大约10个不同的站点上检查了公式,找不到任何错误,但是结果仍然没有意义。

    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);
    }

I found my own error. 我发现了自己的错误。 The mistake is in the RotateAboutY() method above. 错误出在上面的RotateAboutY()方法中。 The correct method is like this... 正确的方法是这样的...

    public static Point3D RotateAboutY(Point3D pt1, double aY)
    {
        double angleY = 3.1415926 * aY / 180;

        double x2 = (pt1.Z * Math.Sin(angleY)) + (pt1.X * Math.Cos(angleY));
        double y2 = pt1.Y;
        double z2 = (pt1.Z * Math.Cos(angleY)) - (pt1.X * Math.Sin(angleY));

        return new Point3D(x2, y2, z2);
    }

The short treatment of this topic can be found here with the correct formulas. 这里可以找到正确的公式来对该主题进行简短处理。 There is a more detailed explanation of this topic on Kirupa.com where the correct formulas are also included. Kirupa.com上对此主题有更详细的说明,其中还包含正确的公式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM