Beispiel #1
0
        public void AxisAngle_ToQuaternion_ToAxisAngle_Negative()
        {
            AxisAngle  aa1, aa2;
            Quaternion q;

            double x, y, z, angle;

            // Test random quaternions
            for (var i = 0; i < 50; i++)
            {
                x     = Random(-100, 100);
                y     = Random(-100, 100);
                z     = Random(-100, 100);
                angle = Random(-360, 0);  // choose only negative angles

                Trace.WriteLine("");
                Trace.WriteLine(x + " " + y + " " + z + " " + angle + " length: " + Geometry.Length(x, y, z));

                aa1 = new AxisAngle(x, y, z, angle);
                q   = aa1.ToQuaternion();    // this method will normalize the Quaternion, as neccesary for spatial rotation representation
                aa2 = q.ToAxisAngle();
                Trace.WriteLine(aa1);
                Trace.WriteLine(q);
                Trace.WriteLine(aa2);

                aa2.Flip();  // from quaternion conversion, aa2 will be inverted. Flip for comparison
                Trace.WriteLine(aa2 + " (flipped)");

                Assert.IsTrue(aa1.IsSimilar(aa2), "Boooo! :(");
            }
        }
Beispiel #2
0
        public void AxisAngle_ToQuaternion_ToAxisAngle_Modulation()
        {
            AxisAngle  aa1, aa2;
            Quaternion q;

            double x, y, z, angle;

            // Test random quaternions
            for (var i = 0; i < 50; i++)
            {
                x     = Random(-100, 100);
                y     = Random(-100, 100);
                z     = Random(-100, 100);
                angle = Random(-1000, 1000);  // test any possible angle

                Trace.WriteLine("");
                Trace.WriteLine(x + " " + y + " " + z + " " + angle + " length: " + Geometry.Length(x, y, z));

                aa1 = new AxisAngle(x, y, z, angle);
                q   = aa1.ToQuaternion();    // this method will normalize the Quaternion, as necessary for spatial rotation representation
                aa2 = q.ToAxisAngle();
                Trace.WriteLine(aa1);
                Trace.WriteLine(q);
                Trace.WriteLine(aa2);

                // If angle wasn't within 'module', modulate it
                if (angle < 0 || angle > 360)
                {
                    aa1.Modulate();
                    q   = aa1.ToQuaternion();
                    aa2 = q.ToAxisAngle();
                    Trace.WriteLine("After modulation:");
                    Trace.WriteLine(aa1);
                    Trace.WriteLine(q);
                    Trace.WriteLine(aa2);
                }

                // Now this should work
                Assert.IsTrue(aa1.IsSimilar(aa2));
            }
        }
Beispiel #3
0
        public void AxisAngle_ToQuaternion_ToAxisAngle_Simple()
        {
            AxisAngle  aa1, aa2;
            Quaternion q;

            double x, y, z, angle;

            // Test random quaternions
            for (var i = 0; i < 50; i++)
            {
                x     = Random(-100, 100);
                y     = Random(-100, 100);
                z     = Random(-100, 100);
                angle = Random(360);  // choose only positive angles, because quaternion coversion will always return a positive rotation in [0, 360]

                Trace.WriteLine("");
                Trace.WriteLine(x + " " + y + " " + z + " " + angle + " length: " + Geometry.Length(x, y, z));

                aa1 = new AxisAngle(x, y, z, angle);
                q   = aa1.ToQuaternion();    // this method will normalize the Quaternion, as neccesary for spatial rotation representation
                aa2 = q.ToAxisAngle();
                Trace.WriteLine(aa1);
                Trace.WriteLine(q);
                Trace.WriteLine(aa2);

                Assert.IsTrue(aa1.IsSimilar(aa2), "Boooo! :(");
            }


            // Test all permutations of unitary components quaternions (including zero)
            for (x = -1; x <= 1; x++)
            {
                for (y = -1; y <= 1; y++)
                {
                    for (z = -1; z <= 1; z++)
                    {
                        for (angle = 0; angle <= 360; angle += 45)
                        {
                            Trace.WriteLine("");
                            Trace.WriteLine(x + " " + y + " " + z + " " + angle + " length: " + Geometry.Length(x, y, z));

                            aa1 = new AxisAngle(x, y, z, angle);
                            q   = aa1.ToQuaternion();
                            aa2 = q.ToAxisAngle();
                            Trace.WriteLine(aa1);
                            Trace.WriteLine(q);
                            Trace.WriteLine(aa2);

                            // Deal with zero angles
                            if (aa1.IsZero())
                            {
                                Assert.IsTrue(aa1.IsZero());
                                Assert.IsTrue(q.IsIdentity());
                                Assert.IsTrue(aa2.IsZero());
                            }
                            else
                            {
                                Assert.IsTrue(aa1.IsSimilar(aa2), "Booooo! :(");
                            }
                        }
                    }
                }
            }
        }