コード例 #1
0
        public static AffineMatrix FromPoint(PointF p)
        {
            AffineMatrix res = new AffineMatrix(3, 1);

            res.Data[0][0] = p.X;
            res.Data[1][0] = p.Y;
            res.Data[2][0] = 1;
            return(res);
        }
コード例 #2
0
 public void Translate(float dx, float dy)
 {
     for (int i = 0; i < points.Count; ++i)
     {
         AffineTransformer t = new AffineTransformer(AffineMatrix.FromPoint(points[i]));
         t.Translate(dx, dy);
         points[i] = t.GetResult().ToPoint();
     }
     RaiseChangedEvent(PolygonChangeType.PointsChanged);
 }
コード例 #3
0
        public static AffineMatrix ScaleMatrix(float width, float height)
        {
            AffineMatrix res = new AffineMatrix(3, 3);

            res.Data[0][0] = width; res.Data[0][1] = 0; res.Data[0][2] = 0;
            res.Data[1][0] = 0; res.Data[1][1] = height; res.Data[1][2] = 0;
            res.Data[2][0] = 0; res.Data[2][1] = 0; res.Data[2][2] = 1;

            return(res);
        }
コード例 #4
0
        public static AffineMatrix TranslateMatrix(float dx, float dy)
        {
            AffineMatrix res = new AffineMatrix(3, 3);

            res.Data[0][0] = 1; res.Data[0][1] = 0; res.Data[0][2] = dx;
            res.Data[1][0] = 0; res.Data[1][1] = 1; res.Data[1][2] = dy;
            res.Data[2][0] = 0; res.Data[2][1] = 0; res.Data[2][2] = 1;

            return(res);
        }
コード例 #5
0
 public void Rotate(float angle, PointF point)
 {
     for (int i = 0; i < points.Count; ++i)
     {
         AffineTransformer t = new AffineTransformer(AffineMatrix.FromPoint(points[i]));
         t.Translate(-point.X, -point.Y);
         t.Rotate(angle);
         t.Translate(point.X, point.Y);
         points[i] = t.GetResult().ToPoint();
     }
     RaiseChangedEvent(PolygonChangeType.PointsChanged);
 }
コード例 #6
0
        public static AffineMatrix RotateMatrix(float angle)
        {
            AffineMatrix res = new AffineMatrix(3, 3);

            double a = Math.PI * angle / 180;

            res.Data[0][0] = (float)Math.Cos(a); res.Data[0][1] = (float)Math.Sin(a); res.Data[0][2] = 0;
            res.Data[1][0] = (float)-Math.Sin(a); res.Data[1][1] = (float)Math.Cos(a); res.Data[1][2] = 0;
            res.Data[2][0] = 0; res.Data[2][1] = 0; res.Data[2][2] = 1;

            return(res);
        }
コード例 #7
0
        public static AffineMatrix MultMatrices(AffineMatrix A, AffineMatrix B)
        {
            AffineMatrix C = new AffineMatrix(A.Rows, B.Columns);

            for (int i = 0; i < A.Rows; i++)
            {
                for (int j = 0; j < B.Columns; j++)
                {
                    for (int k = 0; k < A.Columns; k++)
                    {
                        C.Data[i][j] += A.Data[i][k] * B.Data[k][j];
                    }
                }
            }
            return(C);
        }
コード例 #8
0
        public void Scale(float width, float height)
        {
            float sumX = 0, sumY = 0;

            for (int i = 0; i < points.Count; ++i)
            {
                sumX += points[i].X;
                sumY += points[i].Y;
            }
            PointF transPoint = new PointF(sumX / points.Count, sumY / points.Count);

            for (int i = 0; i < points.Count; ++i)
            {
                AffineTransformer t = new AffineTransformer(AffineMatrix.FromPoint(points[i]));
                t.Translate(-transPoint.X, -transPoint.Y);
                t.Scale(width, height);
                t.Translate(transPoint.X, transPoint.Y);
                points[i] = t.GetResult().ToPoint();
            }
            RaiseChangedEvent(PolygonChangeType.PointsChanged);
        }
コード例 #9
0
 public void Scale(float width, float height)
 {
     matrix = AffineMatrix.MultMatrices(AffineMatrix.ScaleMatrix(width, height), matrix);
 }
コード例 #10
0
 public void Rotate(float angle)
 {
     matrix = AffineMatrix.MultMatrices(AffineMatrix.RotateMatrix(angle), matrix);
 }
コード例 #11
0
 public void Translate(float dx, float dy)
 {
     matrix = AffineMatrix.MultMatrices(AffineMatrix.TranslateMatrix(dx, dy), matrix);
 }
コード例 #12
0
 public AffineTransformer(AffineMatrix m)
 {
     matrix = m;
 }