예제 #1
0
        public static TrnsData ToTrnsData
            (this AffinePos srcPos, int w, int h)
        {
            //inner w h
            var innerh = PosL2(srcPos.LB, srcPos.LT);
            var innerw = PosL2(srcPos.RT, srcPos.LT);


            var trgPos = srcPos.MoveToCenter(new PointD(w / 2.0, h / 2.0)); // ok

            var fcenterX = srcPos.GetCenter().X;
            var fcenterY = srcPos.GetCenter().Y;
            var lcenterX = trgPos.GetCenter().X;
            var lcenterY = trgPos.GetCenter().Y;



            var xshift = lcenterX - fcenterX;
            var yshift = lcenterY - fcenterY;

            var dx = srcPos.LT.X - srcPos.RT.X;
            var dy = srcPos.LT.Y - srcPos.RT.Y;

            double radian;

            if (Abs(dx) < 0.0001)
            {
                radian = 1.5708;
            }
            else if (Abs(dy) < 0.0001)
            {
                radian = 3.14159;
            }
            else
            {
                radian = Math.Atan(dy / dx);
            }
            //var angle_degree = 360 - Math.Atan2(dy, dx) * 180 / Math.PI;
            //double radian;
            //angle_degree %= 360;
            //radian = PI / 180.0 * angle_degree;

            return(new TrnsData()
            {
                H = h,
                W = w,
                XShift = (int)xshift,
                YShift = (int)yshift,
                Innerw = innerw,
                Innterh = innerh,
                XSrcCnter = (int)fcenterX,
                YSrcCnter = (int)fcenterY,
                dX = (int)dx,
                dY = (int)dy,
                Angle = radian,
            });
        }
예제 #2
0
        public static int[,] xytransform(AffinePos srcPos, AffinePos trgPos, int[,] src)
        {
            var h        = src.GetLength(0);
            var w        = src.GetLength(1);
            var fcenterX = srcPos.GetCenter().X;
            var fcenterY = srcPos.GetCenter().Y;
            var lcenterX = trgPos.GetCenter().X;
            var lcenterY = trgPos.GetCenter().Y;
            var xshift   = lcenterX - fcenterX;
            var yshift   = lcenterY - fcenterY;
            var dx       = Abs(srcPos.LT.X - srcPos.RT.X);
            var dy       = Abs(srcPos.LT.Y - srcPos.RT.Y);

            if (dx == 0)
            {
                return(null);
            }
            var angle_degree = 360 - Math.Atan2(dy, dx) * 180 / Math.PI;

            int[,] R = new int[(int)(h + Abs(yshift)), (int)(w + Abs(xshift))];

            for (int j = 0; j < h; j++)
            {
                for (int i = 0; i < w; i++)
                {
                    if (i - xshift >= 0 &&
                        j - yshift >= 0 &&
                        i - xshift < R.GetLength(1) &&
                        j - yshift < R.GetLength(0))
                    {
                        R[(int)(j - yshift), (int)(i - xshift)] = src[j, i];
                    }
                }
            }
            return(R);
        }