示例#1
0
 public virtual void  MoveTo(PointFP point)
 {
     if (!started)
     {
         startPoint.Reset(point);
         started = true;
     }
     currPoint.Reset(point);
 }
示例#2
0
文件: LineFP.cs 项目: nakijun/adasg
        public LineFP GetHeadOutline(int ff_rad)
        {
            PointFP p   = new PointFP(P1.X - P2.X, P1.Y - P2.Y);
            int     len = Length;

            p.Reset(MathFP.Div(-p.Y, len), MathFP.Div(p.X, len));
            p.Reset(MathFP.Mul(p.X, ff_rad), MathFP.Mul(p.Y, ff_rad));
            return(new LineFP(P1.X - p.X, P1.Y - p.Y, P1.X + p.X, P1.Y + p.Y));
        }
示例#3
0
文件: LineFP.cs 项目: nakijun/adasg
        public LineFP GetTailOutline(int ff_rad)
        {
            PointFP c = Center;
            PointFP p = new PointFP(P2.X - c.X, P2.Y - c.Y);

            p.Reset(p.Y, -p.X);
            int dis = PointFP.Distance(PointFP.Origin, p);

            if (dis == 0)
            {
                dis = 1;
            }
            p.Reset(MathFP.Div(MathFP.Mul(p.X, ff_rad), dis), MathFP.Div(MathFP.Mul(p.Y, ff_rad), dis));
            return(new LineFP(P2.X - p.X, P2.Y - p.Y, P2.X + p.X, P2.Y + p.Y));
        }
示例#4
0
文件: LineFP.cs 项目: nakijun/adasg
 public void  Reset(int ff_x1, int ff_y1, int ff_x2, int ff_y2)
 {
     P1.Reset(ff_x1, ff_y1);
     P2.Reset(ff_x2, ff_y2);
 }
示例#5
0
文件: LineFP.cs 项目: nakijun/adasg
        public static bool Intersects(LineFP l1, LineFP l2, PointFP intersection)
        {
            int x = SingleFP.NaN;
            int y = SingleFP.NaN;

            if (intersection != null)
            {
                intersection.Reset(x, y);
            }

            int ax0 = l1.P1.X;
            int ax1 = l1.P2.X;
            int ay0 = l1.P1.Y;
            int ay1 = l1.P2.Y;
            int bx0 = l2.P1.X;
            int bx1 = l2.P2.X;
            int by0 = l2.P1.Y;
            int by1 = l2.P2.Y;

            int adx = (ax1 - ax0);
            int ady = (ay1 - ay0);
            int bdx = (bx1 - bx0);
            int bdy = (by1 - by0);

            if (IsZero(adx) && IsZero(bdx))
            {
                return(IsEqual(ax0, bx0));
            }
            else if (IsZero(ady) && IsZero(bdy))
            {
                return(IsEqual(ay0, by0));
            }
            else if (IsZero(adx))
            {
                // A  vertical
                x = ax0;
                y = IsZero(bdy)?by0:MathFP.Mul(MathFP.Div(bdy, bdx), x - bx0) + by0;
            }
            else if (IsZero(bdx))
            {
                // B vertical
                x = bx0;
                y = IsZero(ady)?ay0:MathFP.Mul(MathFP.Div(ady, adx), x - ax0) + ay0;
            }
            else if (IsZero(ady))
            {
                y = ay0;
                x = MathFP.Mul(MathFP.Div(bdx, bdy), y - by0) + bx0;
            }
            else if (IsZero(bdy))
            {
                y = by0;
                x = MathFP.Mul(MathFP.Div(adx, ady), y - ay0) + ax0;
            }
            else
            {
                int xma = MathFP.Div(ady, adx);                 // slope segment A
                int xba = ay0 - (MathFP.Mul(ax0, xma));         // y intercept of segment A

                int xmb = MathFP.Div(bdy, bdx);                 // slope segment B
                int xbb = by0 - (MathFP.Mul(bx0, xmb));         // y intercept of segment B

                // parallel lines?
                if (xma == xmb)
                {
                    // Need trig functions
                    return(xba == xbb);
                }
                else
                {
                    // Calculate points of intersection
                    // At the intersection of line segment A and B, XA=XB=XINT and YA=YB=YINT
                    x = MathFP.Div((xbb - xba), (xma - xmb));
                    y = (MathFP.Mul(xma, x)) + xba;
                }
            }

            // After the point or points of intersection are calculated, each
            // solution must be checked to ensure that the point of intersection lies
            // on line segment A and B.

            int minxa = MathFP.Min(ax0, ax1);
            int maxxa = MathFP.Max(ax0, ax1);

            int minya = MathFP.Min(ay0, ay1);
            int maxya = MathFP.Max(ay0, ay1);

            int minxb = MathFP.Min(bx0, bx1);
            int maxxb = MathFP.Max(bx0, bx1);

            int minyb = MathFP.Min(by0, by1);
            int maxyb = MathFP.Max(by0, by1);

            if (intersection != null)
            {
                intersection.Reset(x, y);
            }
            return((x >= minxa) && (x <= maxxa) && (y >= minya) && (y <= maxya) && (x >= minxb) && (x <= maxxb) && (y >= minyb) && (y <= maxyb));
        }