示例#1
0
 public Vector2D ApplyToVector(Vector2D v)
 {
     // v is interpreted as a real vector - no translation applies
     return m.ToMatrix2x2() * v;
 }
示例#2
0
 public static T_Viewport GetSelfTransformationFromRotation(SizeF sourceSize, Rotation targetRotation)
 {
     var unitVector = new Vector2D(1, 1);
     var targetSize = Matrix2x2.RotationMatrix(targetRotation) * sourceSize;
     return new T_Viewport(sourceSize, unitVector, targetSize, unitVector, targetRotation);
 }
示例#3
0
        public T_Viewport(SizeF sourceSize, Vector2D sourceUnits,
                          SizeF targetSize, Vector2D targetUnits,
                          Rotation targetRotation)
        {
            this.sourceSize = sourceSize;
            this.sourceUnits = sourceUnits;
            this.targetSize = targetSize;
            this.targetUnits = targetUnits;
            this.targetRotation = targetRotation;

            // create 2D scaling & rotation & axis reflection
            var normalizedTargetSize = Matrix2x2.RotationMatrix(targetRotation.ReverseRotation()) * targetSize;
            float mx = normalizedTargetSize.Width / sourceSize.Width;
            float my = normalizedTargetSize.Height / sourceSize.Height;
            var reflection = Matrix2x2.Unit();
            if (targetUnits.x * sourceUnits.x < 0)
                reflection.x1y1 = -1;
            if (targetUnits.y * sourceUnits.y < 0)
                reflection.x2y2 = -1;
            Matrix2x2 scaleRotateReflect = new Matrix2x2(mx, 0, 0, my) * Matrix2x2.RotationMatrix(targetRotation) * reflection;

            // combine with translation into a 3D matrix
            m = new Matrix3x3(scaleRotateReflect);
            if (m.x1y1 < 0)
                m.x3y1 = normalizedTargetSize.Width;
            if (m.x1y2 < 0)
                m.x3y2 = normalizedTargetSize.Width;
            if (m.x2y1 < 0)
                m.x3y1 = normalizedTargetSize.Height;
            if (m.x2y2 < 0)
                m.x3y2 = normalizedTargetSize.Height;

        }
示例#4
0
 public static RectangleF operator *(RectangleF r, T_StretchMove2D tsm)
 {
     Vector2D p1 = new Vector2D((float)r.Right, (float)r.Top) * tsm;
     Vector2D p2 = new Vector2D((float)r.Left, (float)r.Bottom) * tsm;
     return Vector2D.Rect(p1, p2);
 }
示例#5
0
        // members

        public Vector2D ApplyTo(Vector2D v)
        {
            return new Vector2D(v.x * mx, v.y * my) + t;
        }
示例#6
0
 // two Vector2D to Rectangle
 public static RectangleF Rect(Vector2D v1, Vector2D v2)
 {
     // returns the Rectangle defined by the diagonal points v1 and v2
     float x = Math.Min(v1.x, v2.x);
     float sx = Math.Abs(v1.x - v2.x);
     float y = Math.Min(v1.y, v2.y);
     float sy = Math.Abs(v1.y - v2.y);
     return new RectangleF(x, y, sx, sy);
 }
示例#7
0
 public T_StretchMove2D(float mx, float my, float tx, float ty)
 {
     this.mx = mx;
     this.my = my;
     this.t = new Vector2D(tx, ty);
 }
示例#8
0
 // returns the minimum by components of this and the given vector
 public Vector2D MinByComponent(Vector2D v)
 {
     return new Vector2D(Math.Min(x, v.x), Math.Min(y, v.y));
 }
示例#9
0
 // returns the maximum by components of this and the given vector
 public Vector2D MaxByComponent(Vector2D v)
 {
     return new Vector2D(Math.Max(x, v.x), Math.Max(y, v.y));
 }
示例#10
0
        // returns true, if (this) points into the given rectangle
        public bool IsIn(Vector2D r1, Vector2D r2)
        {
            float _x = Math.Min(r1.x, r2.x);
            float _xs = Math.Abs(r1.x - r2.x);
            float _y = Math.Min(r1.y, r2.y);
            float _ys = Math.Abs(r1.y - r2.y);

            if (y < _y || y > _y + _ys)
                return false;
            if (x < _x || x > _x + _xs)
                return false;

            return true;
        }
示例#11
0
 // returns the dot product (this . with)
 public float Dot(Vector2D with)
 {
     return x * with.x + y * with.y;
 }
示例#12
0
 // returns (this x v)
 public Vector3D Cross(Vector2D with)
 {
     float _z = x * with.y - y * with.x;
     return new Vector3D(0, 0, _z);
 }
示例#13
0
        // returns (this - v)
        public Vector2D Subtract(Vector2D v)
        {
            float _x = x - v.x;
            float _y = y - v.y;

            return new Vector2D(_x, _y);
        }
示例#14
0
        // members

        // returns (this + v)
        public Vector2D Add(Vector2D v)
        {
            float _x = x + v.x;
            float _y = y + v.y;

            return new Vector2D(_x, _y);
        }