Beispiel #1
0
        public TS_point Intersection(TS_line line2)
        {
            double a1 = SlopeA;
            double b1 = InterceptB;
            double a2 = line2.SlopeA;
            double b2 = line2.InterceptB;

            if (TS_point.TS_AreDoublesEqual(a1, a2))
            {
                return(new TS_point(Double.NaN, Double.NaN));
            }

            /*
             * double x = (b1-b2)/(a2-a1);
             * double y = (a2*b1 - b2*a1)/(a2-a1);
             * return new TS_point(x,y);
             */

            double A1 = GenA;
            double A2 = line2.GenA;
            double B1 = GenB;
            double B2 = line2.GenB;
            double C1 = GenC;
            double C2 = line2.GenC;

            double D1 = (B2 - B1) / (A1 - A2);
            double D2 = (C2 - C1) / (A1 - A2);

            double y = -(A1 * D2 + C1) / (A1 * D1 + B1);
            double x = D1 * y + D2;

            return(new TS_point(x, y));
        }
Beispiel #2
0
 public TS_side(TS_point StartPoint, TS_point EndPoint)
 {
     this.StartPoint = StartPoint;
     this.EndPoint   = EndPoint;
     Line            = new TS_line(StartPoint, EndPoint);
     //ReCalcMe();
 }
Beispiel #3
0
        public bool IsCrossedWith(TS_line line2)
        {
            TS_point crossPoint = Intersection(line2);

            if (Double.IsNaN(crossPoint.X) || Double.IsNaN(crossPoint.Y))
            {
                return(false);
            }
            return(true);
        }
Beispiel #4
0
        public TS_point CrossedPoint(TS_line line2)
        {
            TS_point point = Line.Intersection(line2);

            if (IsContain(point))
            {
                return(point);
            }

            return(new TS_point());
        }
Beispiel #5
0
 public bool IsCrossedWith(TS_line line2)
 {
     if (Line.IsCrossedWith(line2))
     {
         TS_point crossPoint = Line.Intersection(line2);
         if (IsContain(crossPoint))
         {
             return(true);
         }
     }
     return(false);
 }
        public bool IsPointInside(TS_point point)
        {
            if (IsAVertex(point))
            {
                return(false);
            }

            foreach (var side in Sides)
            {
                if (side.IsContain(point))
                {
                    return(false);
                }
            }

            TS_line horLine = new TS_line(0, point.Y);
            ObservableCollectionEx <TS_point> horPoints = new ObservableCollectionEx <TS_point>();

            foreach (var side in Sides)
            {
                TS_point pointX = side.CrossedPoint(horLine);
                if (pointX.X > point.X && !horPoints.Contains(pointX))
                {
                    horPoints.Add(pointX);
                }
            }

            int countH = horPoints.Count;

            if (countH % 2 != 0)
            {
                return(true);
            }

            TS_line         vertLine   = new TS_line(1, 0, -point.X);
            List <TS_point> vertPoints = new List <TS_point>();

            foreach (var side in Sides)
            {
                TS_point pointY = side.CrossedPoint(vertLine);
                if (pointY.Y > point.Y && !vertPoints.Contains(pointY))
                {
                    vertPoints.Add(pointY);
                }
            }

            int countV = vertPoints.Count;

            if (countV % 2 != 0)
            {
                return(true);
            }

            TS_line         horLineL   = new TS_line(0, point.Y);
            List <TS_point> horPointsL = new List <TS_point>();

            foreach (var side in Sides)
            {
                TS_point pointX = side.CrossedPoint(horLineL);
                if (pointX.X > point.X && !horPointsL.Contains(pointX))
                {
                    horPointsL.Add(pointX);
                }
            }

            int countHL = horPointsL.Count;

            if (countHL % 2 != 0)
            {
                return(true);
            }

            List <TS_point> vertPointsD = new List <TS_point>();

            foreach (var side in Sides)
            {
                TS_point pointY = side.CrossedPoint(vertLine);
                if (pointY.Y > point.Y && !vertPointsD.Contains(pointY))
                {
                    vertPointsD.Add(pointY);
                }
            }

            int countVD = vertPointsD.Count;

            if (countVD % 2 != 0)
            {
                return(true);
            }

            return(false);
        }