Пример #1
0
        public void Point3dDotProductTest()
        {
            var p1 = new Point3d(1, 2, 3);
            var p2 = new Point3d(3, 2, 1);
            var r  = p1.Dot(p2);

            Assert.AreEqual(r, 10);
        }
Пример #2
0
        /**
         * Returns the coordinates for <code>num</code> randomly
         * chosen points which are degenerate which respect
         * to the specified dimensionality.
         *
         * @param num number of points to produce
         * @param dimen dimensionality of degeneracy: 0 = coincident,
         * 1 = colinear, 2 = coplaner.
         * @return array of coordinate values
         */
        private double[] randomDegeneratePoints(int num, int dimen)
        {
            double[] coords = new double[num * 3];
            Point3d  pnt    = new Point3d();

            Point3d _base = new Point3d();

            _base.SetRandom(-1, 1, rand);

            double tol = DOUBLE_PREC;

            if (dimen == 0)
            {
                for (int i = 0; i < num; i++)
                {
                    pnt.Set(_base);
                    randomlyPerturb(pnt, tol);
                    coords[i * 3 + 0] = pnt.x;
                    coords[i * 3 + 1] = pnt.y;
                    coords[i * 3 + 2] = pnt.z;
                }
            }
            else if (dimen == 1)
            {
                Vector3d u = new Vector3d();
                u.SetRandom(-1, 1, rand);
                u.Normalize();
                for (int i = 0; i < num; i++)
                {
                    double a = 2 * (rand.NextDouble() - 0.5);
                    pnt.Scale(a, u);
                    pnt.Add(_base);
                    randomlyPerturb(pnt, tol);
                    coords[i * 3 + 0] = pnt.x;
                    coords[i * 3 + 1] = pnt.y;
                    coords[i * 3 + 2] = pnt.z;
                }
            }
            else   // dimen == 2
            {
                Vector3d nrm = new Vector3d();
                nrm.SetRandom(-1, 1, rand);
                nrm.Normalize();
                for (int i = 0; i < num; i++)  // compute a random point and project it to the plane
                {
                    Vector3d perp = new Vector3d();
                    pnt.SetRandom(-1, 1, rand);
                    perp.Scale(pnt.Dot(nrm), nrm);
                    pnt.Sub(perp);
                    pnt.Add(_base);
                    randomlyPerturb(pnt, tol);
                    coords[i * 3 + 0] = pnt.x;
                    coords[i * 3 + 1] = pnt.y;
                    coords[i * 3 + 2] = pnt.z;
                }
            }
            return(coords);
        }
Пример #3
0
        public void Point3d_Dot_Oddball()
        {
            Point3d a = new Point3d(0.001, 0.0001, 0.00001),
                 b = new Point3d(473.6, 9.0, 1.1);
            double actual = a.Dot(b);
            double expected = 0.474511;

            Assert.That(actual, Is.EqualTo(expected).Within(1).Ulps);
        }
Пример #4
0
        public void Point3d_Dot_123_456()
        {
            Point3d a = new Point3d(1.0, 2.0, 3.0),
                 b = new Point3d(4.0, 5.0, 6.0);
            double actual = a.Dot(b);
            double expected = 32.0;

            Assert.That(actual, Is.EqualTo(expected).Within(1).Ulps);
        }
        public void Point3d_Dot_Oddball()
        {
            Point3d a       = new Point3d(0.001, 0.0001, 0.00001),
                    b       = new Point3d(473.6, 9.0, 1.1);
            double actual   = a.Dot(b);
            double expected = 0.474511;

            Assert.That(actual, Is.EqualTo(expected).Within(1).Ulps);
        }
        public void Point3d_Dot_123_456()
        {
            Point3d a       = new Point3d(1.0, 2.0, 3.0),
                    b       = new Point3d(4.0, 5.0, 6.0);
            double actual   = a.Dot(b);
            double expected = 32.0;

            Assert.That(actual, Is.EqualTo(expected).Within(1).Ulps);
        }