Exemple #1
0
 /// <summary>
 /// Multiplies matrix with a V4f.
 /// </summary>
 public static V4f Multiply(M22f mat, V4f vec)
 {
     return(new V4f(mat.M00 * vec.X + mat.M01 * vec.Y,
                    mat.M10 * vec.X + mat.M11 * vec.Y,
                    vec.Z,
                    vec.W));
 }
Exemple #2
0
 /// <summary>
 /// Multiplacation of a <see cref="Scale3f"/> with a <see cref="V4f"/>.
 /// </summary>
 public static V4f Multiply(Scale3f scale, V4f vec)
 {
     return(new V4f(scale.X * vec.X,
                    scale.Y * vec.Y,
                    scale.Z * vec.Z,
                    vec.W));
 }
Exemple #3
0
        public static V4f Transform(this Rot2f rot, V4f v)
        {
            float a = Fun.Cos(rot.Angle);
            float b = Fun.Sin(rot.Angle);

            return(new V4f(a * v.X + -b * v.Y,
                           b * v.X + a * v.Y,
                           v.Z, v.W));
        }
Exemple #4
0
        /// <summary>
        /// Calculates the centroid for a given set of V4fs.
        /// </summary>
        public static V4f ComputeCentroid(this V4f[] vectors)
        {
            V4f sum = V4f.Zero;

            for (var i = 0; i < vectors.Length; i++)
            {
                sum += vectors[i];
            }

            return(sum / (float)vectors.Length);
        }
Exemple #5
0
        /// <summary>
        /// Calculates the centroid for a given set of V4fs.
        /// </summary>
        public static V4f ComputeCentroid(this V4f[] vectors, int[] indices)
        {
            V4f sum = V4f.Zero;

            for (var i = 0; i < indices.Length; i++)
            {
                sum += vectors[indices[i]];
            }

            return(sum / (float)indices.Length);
        }
Exemple #6
0
        /// <summary>
        /// Calculates the sum for a given set of V4fs.
        /// </summary>
        public static V4f Sum(this IEnumerable <V4f> vectors)
        {
            V4f sum = V4f.Zero;

            foreach (var e in vectors)
            {
                sum += e;
            }

            return(sum);
        }
Exemple #7
0
        /// <summary>
        /// Calculates the sum for a given set of V4fs.
        /// </summary>
        public static V4f Sum(this V4f[] vectors)
        {
            V4f sum = V4f.Zero;

            for (var i = 0; i < vectors.Length; i++)
            {
                sum += vectors[i];
            }

            return(sum);
        }
Exemple #8
0
        /// <summary>
        /// Calculates a weighted centroid for a given array of V4fs.
        /// </summary>
        public static V4f ComputeCentroid(this V4f[] vectors, float[] weights)
        {
            V4f   sum       = V4f.Zero;
            float weightSum = 0;

            for (int i = 0; i < vectors.Length; i++)
            {
                sum       += weights[i] * vectors[i];
                weightSum += weights[i];
            }

            return(sum / weightSum);
        }
Exemple #9
0
        /// <summary>
        /// Calculates the centroid for a given set of V4fs.
        /// </summary>
        public static V4f ComputeCentroid(this IEnumerable <V4f> vectors)
        {
            V4f sum   = V4f.Zero;
            int count = 0;

            foreach (var e in vectors)
            {
                sum += e;
                count++;
            }

            return(sum / (float)count);
        }
Exemple #10
0
        /// <summary>
        /// Calculates a weighted centroid for vectors and weights given by indices.
        /// Sum(vectors[indices[i]] * weights[indices[i]]) / Sum(weights[indices[i]].
        /// </summary>
        public static V4f ComputeCentroid(this V4f[] vectors, float[] weights, int[] indices)
        {
            V4f   sum       = V4f.Zero;
            float weightSum = 0;

            for (int i = 0; i < indices.Length; i++)
            {
                var w = weights[indices[i]];
                sum       += w * vectors[indices[i]];
                weightSum += w;
            }

            return(sum / weightSum);
        }
        public static V4f Multiply(Rot2f rot, V4f vec)
        {
            float a = (float)System.Math.Cos(rot.Angle);
            float b = (float)System.Math.Sin(rot.Angle);

            return(new V4f(a * vec.X +
                           b * vec.Y,

                           -b * vec.X +
                           a * vec.Y,

                           vec.Z,

                           vec.W));
        }
Exemple #12
0
 public static V4f InvTransform(this Rot2f rot, V4f v)
 => Transform(rot.Inverse, v);
 public void Write(V4f x)
 {
     Write(x.X); Write(x.Y); Write(x.Z); Write(x.W);
 }
 public QuaternionF(V4f v)
 {
     W = v.X;
     X = v.Y; Y = v.Z; Z = v.W;
 }
Exemple #15
0
 /// <summary>Computes MD5 hash of given data.</summary>
 public static Guid ComputeMd5Hash(this V4f x)
 => ComputeMd5Hash(bw => { bw.Write(x.X); bw.Write(x.Y); bw.Write(x.Z); bw.Write(x.W); });