Пример #1
0
        public void DotProduct()
        {
            // 0°
            Assert.AreEqual(1.0, Vector4D.Dot(Vector4D.UnitX, Vector4D.UnitX));
            Assert.AreEqual(1.0, Vector4D.Dot(Vector4D.UnitY, Vector4D.UnitY));
            Assert.AreEqual(1.0, Vector4D.Dot(Vector4D.UnitZ, Vector4D.UnitZ));
            Assert.AreEqual(1.0, Vector4D.Dot(Vector4D.UnitW, Vector4D.UnitW));

            // 180°
            Assert.AreEqual(-1.0, Vector4D.Dot(Vector4D.UnitX, -Vector4D.UnitX));
            Assert.AreEqual(-1.0, Vector4D.Dot(Vector4D.UnitY, -Vector4D.UnitY));
            Assert.AreEqual(-1.0, Vector4D.Dot(Vector4D.UnitZ, -Vector4D.UnitZ));
            Assert.AreEqual(-1.0, Vector4D.Dot(Vector4D.UnitW, -Vector4D.UnitW));

            // 90°
            Assert.AreEqual(0.0, Vector4D.Dot(Vector4D.UnitX, Vector4D.UnitY));
            Assert.AreEqual(0.0, Vector4D.Dot(Vector4D.UnitY, Vector4D.UnitZ));
            Assert.AreEqual(0.0, Vector4D.Dot(Vector4D.UnitZ, Vector4D.UnitW));
            Assert.AreEqual(0.0, Vector4D.Dot(Vector4D.UnitW, Vector4D.UnitX));

            // 45°
            double angle = Math.Acos(Vector4D.Dot(new Vector4D(1, 1, 0, 0).Normalized, Vector4D.UnitX));

            Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(45.0), angle));
            angle = Math.Acos(Vector4D.Dot(new Vector4D(0, 1, 1, 0).Normalized, Vector4D.UnitY));
            Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(45.0), angle));
            angle = Math.Acos(Vector4D.Dot(new Vector4D(1, 0, 1, 0).Normalized, Vector4D.UnitZ));
            Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(45.0), angle));
            angle = Math.Acos(Vector4D.Dot(new Vector4D(1, 0, 0, 1).Normalized, Vector4D.UnitW));
            Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(45.0), angle));
        }
Пример #2
0
        public void Dot()
        {
            Scalar expected = -(Value * Value * 4);

            UnitHelper.RefOperationTester <Vector4D, Vector4D, Scalar>(op1, op2, expected, Vector4D.Dot, "Dot");
            Assert.AreEqual(expected, op1 * op2, "Operator");
            Assert.AreEqual(expected, Vector4D.Dot(op1, op2), "Method");
        }
Пример #3
0
        /// <summary>
        /// Determines whether the specified matrix is a valid pose matrix.
        /// </summary>
        /// <param name="matrix">The matrix.</param>
        /// <returns>
        /// <see langword="true"/> if the specified matrix is a valid pose matrix; otherwise,
        /// <see langword="false"/>.
        /// </returns>
        /// <remarks>
        /// This method makes a simple, low-performance test.
        /// </remarks>
        public static bool IsValid(Matrix44D matrix)
        {
            Vector4D v1 = matrix * Vector4D.UnitX;
            Vector4D v2 = matrix * Vector4D.UnitY;
            Vector4D v3 = matrix * Vector4D.UnitZ;

            return(Numeric.AreEqual(v1.LengthSquared, 1) &&
                   Numeric.AreEqual(v2.LengthSquared, 1) &&
                   Numeric.AreEqual(v3.LengthSquared, 1) &&
                   Numeric.IsZero(Vector4D.Dot(v1, v2)) &&
                   Numeric.IsZero(Vector4D.Dot(v2, v3)) &&
                   Numeric.IsZero(Vector4D.Dot(v1, v3)) &&
                   Numeric.AreEqual(1.0, matrix.Determinant) &&
                   Numeric.IsZero(matrix.M30) &&
                   Numeric.IsZero(matrix.M31) &&
                   Numeric.IsZero(matrix.M32) &&
                   Numeric.AreEqual(matrix.M33, 1));
        }
Пример #4
0
        private Matrix3D QuatToMatrix3d(Vector4D q)
        {
            double n = q.Dot(q);
            double s = (n > 0.0) ? (2.0 / n) : 0.0f;

            double xs, ys, zs;
            double wx, wy, wz;
            double xx, xy, xz;
            double yy, yz, zz;

            xs = q.x * s;  ys = q.y * s;  zs = q.z * s;
            wx = q.w * xs; wy = q.w * ys; wz = q.w * zs;
            xx = q.x * xs; xy = q.x * ys; xz = q.x * zs;
            yy = q.y * ys; yz = q.y * zs; zz = q.z * zs;

            Matrix3D m = new Matrix3D();

            m[0, 0] = 1.0 - (yy + zz); m[1, 0] = xy - wz;  m[2, 0] = xz + wy;
            m[0, 1] = xy + wz;  m[1, 1] = 1.0 - (xx + zz); m[2, 1] = yz - wx;
            m[0, 2] = xz - wy;  m[1, 2] = yz + wx;  m[2, 2] = 1.0 - (xx + yy);
            return(m);
        }
		private Matrix4D QuatToMatrix4d(Vector4D q)
		{
			double n = q.Dot(q);
			double s = (n > 0.0) ? (2.0 / n) : 0.0f;

			double xs, ys, zs;
			double wx, wy, wz;
			double xx, xy, xz;
			double yy, yz, zz;
			xs = q.x * s; ys = q.y * s; zs = q.z * s;
			wx = q.w * xs; wy = q.w * ys; wz = q.w * zs;
			xx = q.x * xs; xy = q.x * ys; xz = q.x * zs;
			yy = q.y * ys; yz = q.y * zs; zz = q.z * zs;

			Matrix4D m = new Matrix4D();
			m[0, 0] = 1.0 - (yy + zz); m[1, 0] = xy - wz; m[2, 0] = xz + wy;
			m[0, 1] = xy + wz; m[1, 1] = 1.0 - (xx + zz); m[2, 1] = yz - wx;
			m[0, 2] = xz - wy; m[1, 2] = yz + wx; m[2, 2] = 1.0 - (xx + yy);
			m[3, 3] = 1.0;
			return m;
		}
Пример #6
0
        public void Dot()
        {
            Vector4D a = new Vector4D(1.0, 2.0, 3.0, 4.0);
            Vector4D b = new Vector4D(4.0, 5.0, 6.0, 7.0);

            double dot = a.Dot(b);
            Assert.AreEqual(1.0 * 4.0 + 2.0 * 5.0 + 3.0 * 6.0 + 4.0 * 7.0, dot, 1e-14);
        }