コード例 #1
0
        public override GlPointR2[] getIntersection(GlPolygon POLY)
        {
            List <GlPointR2> Intersections = new List <GlPointR2>();

            GlLineR2 fCurLine = new GlLineR2(this[this.CountOfPoints - 1], new GlVectorR2(this[0].X - this[this.CountOfPoints - 1].X, this[0].Y - this[this.CountOfPoints - 1].Y));

            GlPointR2[] faultInter = fCurLine.getIntersection(POLY);
            foreach (GlPointR2 j in faultInter)
            {
                if (new GlLineSegment(this[this.CountOfPoints - 1], this[0]).isPointBelongs(j))
                {
                    Intersections.Add(j);
                }
            }

            for (int i = 0; i < this.CountOfPoints - 1; i++)
            {
                fCurLine   = new GlLineR2(this[i], new GlVectorR2(this[i + 1].X - this[i].X, this[i + 1].Y - this[i].Y));
                faultInter = fCurLine.getIntersection(POLY);
                foreach (GlPointR2 j in faultInter)
                {
                    if (new GlLineSegment(this[i], this[i + 1]).isPointBelongs(j))
                    {
                        Intersections.Add(j);
                    }
                }
            }

            return(Intersections.ToArray());
        }
コード例 #2
0
        public override GlPointR2[] getIntersection(GlPolygon POLY)
        {
            if (POLY == null || POLY.CountOfPoints == 0)
            {
                return new GlPointR2[] { }
            }
            ;

            GlPointR2[] Intersections        = new GlPointR2[POLY.CountOfPoints];
            int         countOfIntersections = 0;

            GlPointR2[] faultInter = new GlLineR2(POLY[POLY.CountOfPoints - 1], new GlVectorR2(POLY[0].X - POLY[POLY.CountOfPoints - 1].X, POLY[0].Y - POLY[POLY.CountOfPoints - 1].Y)).getIntersection(this);

            if (faultInter.Length == 1 && new GlLineSegment(POLY[0], POLY[POLY.CountOfPoints - 1]).isPointBelongs(faultInter[0]))
            {
                Intersections[countOfIntersections++] = faultInter[0];
            }

            for (int i = 0; i < POLY.CountOfPoints - 1; i++)
            {
                faultInter = new GlLineR2(POLY[i], new GlVectorR2(POLY[i + 1].X - POLY[i].X, POLY[i + 1].Y - POLY[i].Y)).getIntersection(this);

                if (faultInter.Length == 1 && new GlLineSegment(POLY[i + 1], POLY[i]).isPointBelongs(faultInter[0]))
                {
                    Intersections[countOfIntersections++] = faultInter[0];
                }
            }

            GlPointR2[] result = new GlPointR2[countOfIntersections];
            Array.Copy(Intersections, result, countOfIntersections);
            return(result);
        }
コード例 #3
0
        public override GlFigure getScaled(float scale)
        {
            GlPointR2 C = new GlPointR2(this.Center);

            C.moveTo(C.X * scale, C.Y * scale);

            GlPolygon PR = new GlPolygon(C);

            for (int i = 0; i < this.CountOfPoints; i++)
            {
                GlPointR2 P = this[i];
                P.moveTo(P.X * scale, P.Y * scale);
                PR.AddVertex(new GlPointR2(P));
            }

            PR.moveTo(this.Center.X, this.Center.Y);
            return(PR);
        }
コード例 #4
0
ファイル: GlCurve.cs プロジェクト: Cesar18102/GeometryDLL
        public override GlPointR2[] getIntersection(GlPolygon POLY)
        {
            if (POLY == null || POLY.CountOfPoints == 0)
            {
                return new GlPointR2[] { }
            }
            ;

            List <GlPointR2> Intersections = new List <GlPointR2>();

            GlPointR2[] faultInter = this.getIntersection(new GlLineR2(POLY[POLY.CountOfPoints - 1],
                                                                       new GlVectorR2(POLY[0].X - POLY[POLY.CountOfPoints - 1].X,
                                                                                      POLY[0].Y - POLY[POLY.CountOfPoints - 1].Y)));

            for (int i = 0; i < faultInter.Length; i++)
            {
                if (new GlLineSegment(POLY[0], POLY[POLY.CountOfPoints - 1]).isPointBelongs(faultInter[i]))
                {
                    Intersections.Add(faultInter[i]);
                }
            }

            for (int i = 0; i < POLY.CountOfPoints - 1; i++)
            {
                faultInter = this.getIntersection(new GlLineR2(POLY[i], new GlVectorR2(POLY[i + 1].X - POLY[i].X, POLY[i + 1].Y - POLY[i].Y)));

                for (int j = 0; j < faultInter.Length; j++)
                {
                    if (new GlLineSegment(POLY[i + 1], POLY[i]).isPointBelongs(faultInter[j]))
                    {
                        Intersections.Add(faultInter[j]);
                    }
                }
            }

            return(Intersections.ToArray());
        }
コード例 #5
0
 /// <summary>
 /// Determines the intersection of a point and a polygon
 /// </summary>
 /// <returns>An array containing a copy of given point if it belongs to the polygon</returns>
 public override GlPointR2[] getIntersection(GlPolygon POLY)
 {
     return(POLY == null ? new GlPointR2[] { } : POLY.getIntersection(this));
 }
コード例 #6
0
ファイル: GlFigure.cs プロジェクト: Cesar18102/GeometryDLL
 /// <summary>
 /// Determines an anmount of points, created by intersection of a figure and a polygon
 /// </summary>
 /// <returns>An array of intersections</returns>
 public abstract GlPointR2[] getIntersection(GlPolygon POLY);
コード例 #7
0
ファイル: GlCurve.cs プロジェクト: Cesar18102/GeometryDLL
        private void DrawPoints(GlRectangle Border, int GlDrawMode)
        {
            if (Border == null || !ActivateDrawStart())
            {
                return;
            }

            ActivateDrawing();

            bool isInside = Border.isPointInside(this[0]);

            GlPolygon ToDraw = new GlPolygon(this.Center);

            if (Border.isPointInside(this[this.CountOfPoints - 1]) != isInside)
            {
                if (!isInside)
                {
                    ToDraw.AddVertex(this[this.CountOfPoints - 1]);
                }

                GlPointR2[] I = new GlLineR2(this[0], new GlVectorR2(this[0].X - this[this.CountOfPoints - 1].X,
                                                                     this[0].Y - this[this.CountOfPoints - 1].Y)).getIntersection(Border);

                if (I.Length == 2)
                {
                    ToDraw.AddVertex(new GlLineSegment(this[this.CountOfPoints - 1], this[0]).isPointBelongs(I[0]) ? I[0] : I[1]);
                }
                else if (I.Length == 1 && new GlLineSegment(this[this.CountOfPoints - 1], this[0]).isPointBelongs(I[0]))
                {
                    ToDraw.AddVertex(I[0]);
                }
            }

            for (int i = 0; i < this.CountOfPoints - 1; i++)
            {
                if (isInside)
                {
                    ToDraw.AddVertex(this[i]);
                }
                if (Border.isPointInside(this[i + 1]) != isInside)
                {
                    GlPointR2[] I = new GlLineR2(this[i], new GlVectorR2(this[i + 1].X - this[i].X,
                                                                         this[i + 1].Y - this[i].Y)).getIntersection(Border);

                    if (I.Length == 2)
                    {
                        ToDraw.AddVertex(new GlLineSegment(this[i], this[i + 1]).isPointBelongs(I[0]) ? I[0] : I[1]);
                    }
                    else if (I.Length == 1 && new GlLineSegment(this[i], this[i + 1]).isPointBelongs(I[0]))
                    {
                        ToDraw.AddVertex(I[0]);
                    }

                    isInside = !isInside;
                }
            }

            Gl.glBegin(GlDrawMode);
            for (int i = 0; i < ToDraw.CountOfPoints; i++)
            {
                if (ToDraw[i] != null)
                {
                    Gl.glVertex2f(ToDraw[i].X, ToDraw[i].Y);
                }
            }
            Gl.glEnd();

            ActivateDrawed();
        }
コード例 #8
0
 public GlPolygon(GlPolygon copyPolygon) :
     this(copyPolygon == null ? new GlPointR2(float.NaN, float.NaN) : copyPolygon.polyCenter,
          copyPolygon == null ? new GlPointR2[] { } : copyPolygon.vertexes)
 {
 }