Exemplo n.º 1
0
        public static Vector3d Tx(this Matrix4d m, Vector3d v)
        {
            var vv = new Vector4d(v.X, v.Y, v.Z, 1);
            var rr = new Vector4d(Vector4d.Dot(m.Column0, vv), Vector4d.Dot(m.Column1, vv), Vector4d.Dot(m.Column2, vv), Vector4d.Dot(m.Column3, vv));

            return(new Vector3d(rr.X, rr.Y, rr.Z));
        }
Exemplo n.º 2
0
    public void Dot()
    {
        for (int i = 0; i < count; i++)
        {
            float ax, ay, az, aw;
            float bx, by, bz, bw;

            ax = UnityEngine.Random.Range(-10F, 10F);
            ay = UnityEngine.Random.Range(-10F, 10F);
            az = UnityEngine.Random.Range(-10F, 10F);
            aw = UnityEngine.Random.Range(-10F, 10F);

            bx = UnityEngine.Random.Range(-10F, 10F);
            by = UnityEngine.Random.Range(-10F, 10F);
            bz = UnityEngine.Random.Range(-10F, 10F);
            bw = UnityEngine.Random.Range(-10F, 10F);

            Vector4 a = new Vector4(ax, ay, az, aw);
            Vector4 b = new Vector4(bx, by, bz, bw);

            Vector4d ad = new Vector4d(ax, ay, az, aw);
            Vector4d bd = new Vector4d(bx, by, bz, bw);

            float  value  = Vector4.Dot(a, b);
            double valued = Vector4d.Dot(ad, bd);

            Assert.True(Approximate(value, valued));
        }
    }
Exemplo n.º 3
0
        /// <summary>
        /// Bestimmt den geometrischen Fehler des angegebenen Vertex in Bezug auf die
        /// Fehlerquadrik Q.
        /// </summary>
        /// <param name="v">
        /// Der Vertex, dessen geometrischer Fehler bestimmt werden soll.
        /// </param>
        /// <param name="q">
        /// Die zugrundeliegende Fehlerquadrik.
        /// </param>
        /// <returns>
        /// Der geometrische Fehler an der Stelle des angegebenen Vertex.
        /// </returns>
        double ComputeVertexError(Vector3d v, Matrix4d q)
        {
            var h = new Vector4d(v, 1);

            // Geometrischer Fehler Δ(v) = vᵀQv.
            return(Vector4d.Dot(Vector4d.Transform(h, q), h));
        }
Exemplo n.º 4
0
        /// <summary>Transform a direction vector by the given Matrix
        /// Assumes the matrix has a bottom row of (0,0,0,1), that is the translation part is ignored.
        /// </summary>
        /// <param name="vec">The vector to transform</param>
        /// <param name="mat">The desired transformation</param>
        /// <returns>The transformed vector</returns>
        public static Vector3d MultiplyVector3d(this Matrix4d mat, Vector4d vec)
        {
            //Vector3d vNew = new Vector3d(mat.Row2);
            //double val = Vector3d.Dot(vNew, vec);

            return(new Vector3d(
                       Vector4d.Dot(new Vector4d(mat.Row0), vec),
                       Vector4d.Dot(new Vector4d(mat.Row1), vec),
                       Vector4d.Dot(new Vector4d(mat.Row2), vec)));
        }
Exemplo n.º 5
0
        public static IEnumerable <object[]> Data(VectorDimensions dimension)
        {
            var objs = new[]
            {
                new object[] { Vector256.Create(0d), Vector256.Create(0d), default(Vector4d) },
                new object[] { Vector256.Create(1d), Vector256.Create(1d), default(Vector4d) },
                new object[] { Vector256.Create(-1d), Vector256.Create(-1d), default(Vector4d) },
                new object[] { Vector256.Create(-1d), Vector256.Create(1d, 4d, 9d, 16d), default(Vector4d) },
                new object[] { Vector256.Create(1d, 2d, 3d, 4d), Vector256.Create(4d, -5d, 6d, 9d), default(Vector4d) },
                new object[] { Vector256.Create(double.PositiveInfinity), Vector256.Create(double.PositiveInfinity), default(Vector4d) },
                new object[] { Vector256.Create(double.PositiveInfinity), Vector256.Create(double.NegativeInfinity), default(Vector4d) },
                new object[] { Vector256.Create(double.NaN), Vector256.Create(double.NegativeInfinity), default(Vector4d) },
                new object[] { Vector256.Create(double.MaxValue, double.MinValue, double.NaN, 0), Vector256.Create(double.MaxValue, double.MinValue, double.NaN, 0), default(Vector4d) },
            };

            foreach (object[] set in objs)
            {
                switch (dimension)
                {
                case VectorDimensions.V2D:
                {
                    Vector2d v1  = TestHelpers.ByValToSlowVector2d(((Vector256 <double>)set[0]));
                    Vector2d v2  = TestHelpers.ByValToSlowVector2d(((Vector256 <double>)set[1]));
                    double   dot = Vector2d.Dot(v1, v2);
                    set[2] = new Vector2d(dot);
                    break;
                }

                case VectorDimensions.V3D:
                {
                    Vector3d v1  = TestHelpers.ByValToSlowVector3d(((Vector256 <double>)set[0]));
                    Vector3d v2  = TestHelpers.ByValToSlowVector3d(((Vector256 <double>)set[1]));
                    double   dot = Vector3d.Dot(v1, v2);
                    set[2] = new Vector3d(dot);
                    break;
                }

                case VectorDimensions.V4D:
                {
                    Vector4d v1  = TestHelpers.ByValToSlowVector4d(((Vector256 <double>)set[0]));
                    Vector4d v2  = TestHelpers.ByValToSlowVector4d(((Vector256 <double>)set[1]));
                    double   dot = Vector4d.Dot(v1, v2);
                    set[2] = new Vector4d(dot);
                    break;
                }

                default:
                    throw new ArgumentException(nameof(dimension));
                }
            }

            return(objs);
        }
Exemplo n.º 6
0
 public static Vector4d Tx(this Matrix4d m, Vector4d v)
 {
     return(new Vector4d(Vector4d.Dot(m.Column0, v), Vector4d.Dot(m.Column1, v), Vector4d.Dot(m.Column2, v), Vector4d.Dot(m.Column3, v)));
 }
Exemplo n.º 7
0
 public void Dot()
 {
     Assert.AreEqual(Vector4d.Dot(Vector4d.One, Vector4d.One), 4);
 }