public bool TestCrossing(MyLine src, double[,] p)
 {
     if (myEnd == src.myBegin)
     {
         return(false);
     }
     if (myBegin == src.myEnd)
     {
         return(false);
     }
     if (!TwoLine2D.CrossRel(new Point(p[myBegin, 0], p[myBegin, 1]), new Point(p[myEnd, 0], p[myEnd, 1]),
                             new Point(p[src.myBegin, 0], p[src.myBegin, 1]), new Point(p[src.myEnd, 0], p[src.myEnd, 1]), out Point t))
     {
         return(false);
     }
     if (!TwoLine2D.TestRelOnLine(TwoLine2D.CrossStatus.And, t.X))
     {
         return(false);
     }
     if (!TwoLine2D.TestRelOnLine(TwoLine2D.CrossStatus.And, t.Y))
     {
         return(false);
     }
     if (Funcs2D.IsEqual(t.X, 0, Funcs2D.Epson) || Funcs2D.IsEqual(t.Y, 0, Funcs2D.Epson))
     {
         return(false);                                                                                                  // prusecik je na zacatku usecky, nezapisu
     }
     f_AddCross(t.X, src.myBegin);
     src.f_AddCross(t.Y, myBegin);
     return(true);
 }
Example #2
0
        //Zkontroluje prubeh zaobleni
        // return   0 = OK
        //					1 bit = je mimo prvni usecku
        //					2 bit = je mimo druhou usecku
        //                  3 bit = body jsou na jedne primce
        public static int TestRounding(Point pt1, Point pt2, Point pt3, double r)
        {
            int    ret = 0;
            double a   = Vector.AngleBetween(pt2.Minus(pt1), pt3.Minus(pt2));

            if (a > 0)
            {
                r = -r;
            }

            // vypocitam prusecik offsetovanych primek
            Point[] p1 = Funcs2D.LineOffset(pt1, pt2, a);
            if (p1 == null)
            {
                ret |= 1;
            }
            Point[] p2 = Funcs2D.LineOffset(pt2, pt3, a);
            if (p2 == null)
            {
                ret |= 2;
            }
            if (ret != 0)
            {
                return(ret);
            }
            if (!TwoLine2D.CrossRel(p1[0], p1[1], p2[0], p2[1], out Point rr))
            {
                return(4);
            }
            if (!TwoLine2D.TestRelOnLine(TwoLine2D.CrossStatus.And, rr.X))
            {
                ret |= 1;
            }
            if (!TwoLine2D.TestRelOnLine(TwoLine2D.CrossStatus.And, rr.Y))
            {
                ret |= 2;
            }
            return(ret);
        }
Example #3
0
        // vrati relativni souradnice pruseciku primky s polygonem
        public static List <double> PolygonLineCrossingRel(IPolygonReader poly, bool closed, Point pt, Vector v)
        {
            if (poly == null)
            {
                throw (new ArgumentNullException("PolygonLineCrossing_rel(poly,..)"));
            }
            List <double> ret = new List <double>();
            int           b, e;

            double[,] p = poly.CopyTo();
            if (closed)
            {
                e = poly.Length - 1;
                b = 0;
            }
            else
            {
                e = 0;
                b = 1;
            }
            Point p1, p2;

            for (int i = b; i < poly.Length; i++)
            {
                b  = e; e = i;
                p1 = new Point(p[b, 0], p[b, 1]);
                p2 = new Point(p[e, 0], p[e, 1]);
                if (TwoLine2D.CrossRel(pt, v, p1, p2.Minus(p1), out Point pr))
                {
                    if (TwoLine2D.TestRelOnLine(TwoLine2D.CrossStatus.And, pr.Y))
                    {
                        ret.Add(pr.X);
                    }
                }
            }
            ret.Sort();
            return(ret);
        }
Example #4
0
        /// <summary>
        /// oblouk tvoreny dvema po sobe jdoucimi useckami a polomerem
        /// takzvane zaobleni rohu
        /// pokud je polomer zaporny vytvori se tzv. vykousnuti  se stredem ve spolecnem bode
        /// objekt se nastavi na empty pokud jsou usecky rovnobezne nebo jedna z nich ma nulovou delku
        /// </summary>
        /// <param name="pt1">pocatecni bod prvni ridici usecky</param>
        /// <param name="pt2">spolecny bod ridicich usecek</param>
        /// <param name="pt3">konecny bod druhe ridici usecky</param>
        /// <param name="radius">polomer zaobleni, zaporny polomer provede vykousnuti</param>
        /// <param name="testPt">pokud se pocatecni nebo koncovy bod vypocita mimo usecku, objekt se nastavi na Empty</param>
        public Arc2D(Point pt1, Point pt2, Point pt3, double radius, bool testPt = false)
        {
            // zjistim smer offsetu
            double a = Vector.AngleBetween(pt2.Minus(pt1), pt3.Minus(pt2));

            if (a > 0)
            {
                a         = -Math.Abs(radius);
                Clockwise = false;
            }
            else
            {
                a         = Math.Abs(radius);
                Clockwise = true;
            }

            // vypocitam prusecik offsetovanych primek
            Point[] p1 = Funcs2D.LineOffset(pt1, pt2, a);
            Point[] p2 = Funcs2D.LineOffset(pt2, pt3, a);
            if (p1 == null || p2 == null || !TwoLine2D.CrossRel(p1[0], p1[1], p2[0], p2[1], out Point rr))
            {
                // tri body na jedne primce
                Begin  = pt1; End = pt3;
                Radius = 0;
                return;
            }
            if (radius > 0)
            {
                if (testPt)
                {
                    if (!TwoLine2D.TestRelOnLine(TwoLine2D.CrossStatus.And, rr.X) || !TwoLine2D.TestRelOnLine(TwoLine2D.CrossStatus.And, rr.Y))
                    {
                        // body jsou mimo usecky
                        Begin  = pt1; End = pt3;
                        Radius = 0;
                        return;
                    }
                }

                // koeficienty prenesu do puvodnich usecek a spocitam body
                Begin  = Funcs2D.PointOnLine(pt1, pt2, rr.X);
                End    = Funcs2D.PointOnLine(pt2, pt3, rr.Y);
                Radius = radius;
            }
            else
            {
                Radius = -radius;
                if (testPt)
                {
                    if (Funcs2D.Distance(pt1, pt2) < Radius || Funcs2D.Distance(pt2, pt3) < Radius)
                    {
                        // body jsou mimo usecky
                        Begin  = pt1; End = pt3;
                        Radius = 0;
                        return;
                    }
                }
                // bod na prvni primce ve vzdalenosti abs(radius) od spolecneho bodu
                Begin = Funcs2D.PointOnLineLen(pt2, pt1, Radius);
                // bod na druhe primce
                End       = Funcs2D.PointOnLineLen(pt2, pt3, Radius);
                Clockwise = !Clockwise;
            }
        }