コード例 #1
0
        public static V2f Multiply(Rot2f rot, V2f vec)
        {
            float a = (float)System.Math.Cos(rot.Angle);
            float b = (float)System.Math.Sin(rot.Angle);

            return(new V2f(a * vec.X + b * vec.Y,
                           -b * vec.X + a * vec.Y));
        }
コード例 #2
0
        /// <summary>
        /// Calculates the centroid for a given set of V2fs.
        /// </summary>
        public static V2f ComputeCentroid(this V2f[] vectors, int[] indices)
        {
            V2f sum = V2f.Zero;

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

            return(sum / (float)indices.Length);
        }
コード例 #3
0
        /// <summary>
        /// Calculates the sum for a given set of V2fs.
        /// </summary>
        public static V2f Sum(this V2f[] vectors)
        {
            V2f sum = V2f.Zero;

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

            return(sum);
        }
コード例 #4
0
        /// <summary>
        /// Calculates the centroid for a given set of V2fs.
        /// </summary>
        public static V2f ComputeCentroid(this V2f[] vectors)
        {
            V2f sum = V2f.Zero;

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

            return(sum / (float)vectors.Length);
        }
コード例 #5
0
        /// <summary>
        /// Calculates the sum for a given set of V2fs.
        /// </summary>
        public static V2f Sum(this IEnumerable <V2f> vectors)
        {
            V2f sum = V2f.Zero;

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

            return(sum);
        }
コード例 #6
0
        /// <summary>
        /// Calculates the centroid for a given set of V2fs.
        /// </summary>
        public static V2f ComputeCentroid(this IEnumerable <V2f> vectors)
        {
            V2f sum   = V2f.Zero;
            int count = 0;

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

            return(sum / (float)count);
        }
コード例 #7
0
        /// <summary>
        /// Calculates a weighted centroid for a given array of V2fs.
        /// </summary>
        public static V2f ComputeCentroid(this V2f[] vectors, float[] weights)
        {
            V2f   sum       = V2f.Zero;
            float weightSum = 0;

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

            return(sum / weightSum);
        }
コード例 #8
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 V2f ComputeCentroid(this V2f[] vectors, float[] weights, int[] indices)
        {
            V2f   sum       = V2f.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);
        }
コード例 #9
0
ファイル: M44_auto.cs プロジェクト: lcl1153406/aardvark.base
        /// <summary>
        ///  Provides perspective projection matrix.
        ///  The parameters describe the dimensions of the view volume.
        /// </summary>
        public static M44f PerspectiveProjectionTransformRH(V2f size, float n, float f)
        {
            float w = size.X;
            float h = size.Y;
            // Fx      0      0      0
            //  0      Fy     0      0
            //  0      0      A      B
            //  0      0      -1     0
            float Fx = 2 * n / w;
            float Fy = 2 * n / h;
            float A  = f / (n - f);
            float B  = n * f / (n - f);
            M44f  P  = new M44f(
                Fx, 0, 0, 0,
                0, Fy, 0, 0,
                0, 0, A, B,
                0, 0, -1, 0);

            return(P);
        }
コード例 #10
0
 /// <summary>
 /// Creates a rigid transformation from a rotation <paramref name="rot"/> and a (subsequent) translation <paramref name="trans"/>.
 /// </summary>
 public Euclidean2f(Rot2f rot, V2f trans)
 {
     Rot   = rot;
     Trans = trans;
 }
コード例 #11
0
 public static bool ApproxEqual(Euclidean2f r0, Euclidean2f r1, float angleTol, float posTol)
 {
     return(V2f.ApproxEqual(r0.Trans, r1.Trans, posTol) && Rot2f.ApproxEqual(r0.Rot, r1.Rot, angleTol));
 }
コード例 #12
0
 /// <summary>
 /// Inverts this rigid transformation (multiplicative inverse).
 /// this = [Rot^T,-Rot^T Trans]
 /// </summary>
 public void Invert()
 {
     Rot.Invert();
     Trans = -Rot.TransformDir(Trans);
 }
コード例 #13
0
 /// <summary>
 /// Transforms point p (p.w is presumed 1.0) by the inverse of this rigid transformation.
 /// </summary>
 public V2f InvTransformPos(V2f p)
 {
     return(InvTransformPos(this, p));
 }
コード例 #14
0
 /// <summary>
 /// Transforms direction vector v (v.w is presumed 0.0) by the inverse of this rigid transformation.
 /// Actually, only the rotation is used.
 /// </summary>
 public V2f InvTransformDir(V2f v)
 {
     return(InvTransformDir(this, v));
 }
コード例 #15
0
 /// <summary>
 /// Transforms point p (p.w is presumed 1.0) by this rigid transformation.
 /// </summary>
 public V2f TransformPos(V2f p)
 {
     return(TransformPos(this, p));
 }
コード例 #16
0
 /// <summary>
 /// Transforms direction vector v (v.w is presumed 0.0) by this rigid transformation.
 /// Actually, only the rotation is used.
 /// </summary>
 public V2f TransformDir(V2f v)
 {
     return(TransformDir(this, v));
 }
コード例 #17
0
 /// <summary>
 /// Transforms a position vector.
 /// </summary>
 public static V2f TransformPos(Rot2f rot, V2f v)
 {
     return((M22f)rot * v);
 }
コード例 #18
0
 /// <summary>
 /// Creates a rigid transformation from a trafo <paramref name="trafo"/>.
 /// </summary>
 public Euclidean2f(Trafo2d trafo)
 {
     Rot   = Rot2f.FromM22f((M22f)trafo.Forward);
     Trans = (V2f)trafo.Forward.C2.XY;
 }
コード例 #19
0
        public static Euclidean2f Parse(string s)
        {
            var x = s.NestedBracketSplitLevelOne().ToArray();

            return(new Euclidean2f(Rot2f.Parse(x[0]), V2f.Parse(x[1])));
        }
コード例 #20
0
 /// <summary>
 /// Transforms a position vector.
 /// </summary>
 public static V2f InvTransformPos(Rot2f rot, V2f v)
 {
     return((M22f)Rot2f.Negate(rot) * v);
 }
コード例 #21
0
 /// <summary>
 /// Transforms a position vector.
 /// </summary>
 public V2f InvTransformPos(V2f v)
 {
     return(Rot2f.InvTransformPos(this, v));
 }
コード例 #22
0
 /// <summary>
 /// Creates a rigid transformation from a rotation matrix <paramref name="rot"/> and a (subsequent) translation <paramref name="trans"/>.
 /// </summary>
 public Euclidean2f(M22f rot, V2f trans)
 {
     Rot   = Rot2f.FromM22f(rot);
     Trans = trans;
 }
コード例 #23
0
 /// <summary>
 /// Returns the outer product (tensor-product) of v1 * v2^T as a 3x3 Matrix.
 /// </summary>
 public static M22f OuterProduct(this V2f v1, V2f v2)
 {
     return(new M22f(
                v2.X * v1.X, v2.Y * v1.X,
                v2.X * v1.Y, v2.Y * v1.Y));
 }
コード例 #24
0
 /// <summary>
 /// Transforms direction vector v (v.w is presumed 0.0) by rigid transformation r.
 /// Actually, only the rotation is used.
 /// </summary>
 public static V2f TransformDir(Euclidean2f r, V2f v)
 {
     return(r.Rot.TransformDir(v));
 }
コード例 #25
0
 /// <summary>
 /// Transforms point p (p.w is presumed 1.0) by rigid transformation r.
 /// </summary>
 public static V2f TransformPos(Euclidean2f r, V2f p)
 {
     return(r.Rot.TransformPos(p) + r.Trans);
 }
コード例 #26
0
 /// <summary>
 /// Multiplacation of a <see cref="Scale3f"/> with a <see cref="V2f"/>.
 /// </summary>
 public static V2f Multiply(Scale3f scale, V2f v)
 {
     return(new V2f(v.X * scale.X, v.Y * scale.Y));
 }
コード例 #27
0
 /// <summary>
 /// Transforms point p (p.w is presumed 1.0) by the inverse of the rigid transformation r.
 /// </summary>
 public static V2f InvTransformPos(Euclidean2f r, V2f p)
 {
     return(r.Rot.InvTransformPos(p - r.Trans));
 }