简体   繁体   中英

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. 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. I only need to rotate the data 5-20 degrees so I don't think I need quaternions to avoid gimble lock. 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. I've checked the formulas with about 10 different sites and can't find any errors but the results still don't make sense.

    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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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