Esempio n. 1
0
        protected bool Intersect(int Vertex1Ind, int Vertex2Ind, int Vertex3Ind)
        {
            double S1, S2, S3;

            Vertex1Ind %= VertexCount;
            Vertex2Ind %= VertexCount;
            Vertex3Ind %= VertexCount;
            for (int i = 0; i < VertexCount; i++)
            {
                if ((i == Vertex1Ind) || (i == Vertex2Ind) || (i == Vertex3Ind))
                {
                    continue;
                }
                S1 = Geom2d.Square(Vertexes[Vertex1Ind], Vertexes[Vertex2Ind], Vertexes[i]);
                S2 = Geom2d.Square(Vertexes[Vertex2Ind], Vertexes[Vertex3Ind], Vertexes[i]);
                if (((S1 < 0) && (S2 > 0)) || ((S1 > 0) && (S2 < 0)))
                {
                    continue;
                }
                S3 = Geom2d.Square(Vertexes[Vertex3Ind], Vertexes[Vertex1Ind], Vertexes[i]);
                if (((S3 >= 0) && (S2 >= 0)) || ((S3 <= 0) && (S2 <= 0)))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 2
0
        public void UpdatePolygon()
        {
            if (VertexCount >= 3)
            {
                int i;
                convexity = 1;
                square2   = Geom2d.Square(Vertexes[VertexCount - 1], Vertexes[0], Vertexes[1]);
                double S;
                for (i = 0; i <= VertexCount - 3; i++)
                {
                    S = Geom2d.Square(Vertexes[i], Vertexes[i + 1], Vertexes[i + 2]);
                    if (((square2 < 0) && (S > 0)) || ((square2 > 0) && (S < 0)))
                    {
                        convexity = -1;
                    }
                    else
                    if ((S == 0) && (square2 == 0))
                    {
                        convexity = 0;
                    }
                    square2 += S;
                }

                S = Geom2d.Square(Vertexes[VertexCount - 2], Vertexes[VertexCount - 1], Vertexes[0]);
                if (((square2 < 0) && (S > 0)) || ((square2 > 0) && (S < 0)))
                {
                    convexity = -1;
                }
                else
                if ((S == 0) && (square2 == 0))
                {
                    convexity = 0;
                }
                square2 += S;

                /*int High = VertexCount - 1;
                 * PointD O = new PointD();
                 * for (i = 0; i < High; i++)
                 * for (int j = i + 2; j < High; j++)
                 * if (Geom2d.Intersection(Vertexes[i], Vertexes[i + 1], Vertexes[j], Vertexes[j + 1], out O) == 1)
                 * {
                 * self_intersection = 1;
                 * break;
                 * }
                 * if (self_intersection != 1)
                 * for (i = 1; i < High - 1; i++)
                 * if (Geom2d.Intersection(Vertexes[i], Vertexes[i + 1], Vertexes[High], Vertexes[0], out O) == 1)
                 * self_intersection = 1;*/
            }
            else
            {
                square2           = 0;
                convexity         = 0;
                self_intersection = 0;
            }
        }
Esempio n. 3
0
        public void ConvexDivide(bool Triangulation)
        {
            PointDArray TempPolygon = new PointDArray(this);

            ConvPolygons = new List <List <PointD> >();
            int CPH = -1;

            int begin_ind = 0;
            int cur_ind;

            //if (Square(TempPolygon) < 0)
            //    TempPolygon.Reverse();

            while (TempPolygon.Count >= 3)
            {
                while ((Geom2d.Square(TempPolygon[begin_ind], TempPolygon[begin_ind + 1], TempPolygon[begin_ind + 2]) < 0) ||
                       (Intersect(begin_ind, begin_ind + 1, begin_ind + 2) == true))
                {
                    begin_ind++;
                }

                cur_ind = begin_ind + 1;
                ConvPolygons.Add(new List <PointD>());
                CPH++;
                ConvPolygons[CPH].Add(TempPolygon[begin_ind]);
                ConvPolygons[CPH].Add(TempPolygon[cur_ind]);
                ConvPolygons[CPH].Add(TempPolygon[begin_ind + 2]);

                if (Triangulation == false)
                {
                    while ((Geom2d.Square(TempPolygon[cur_ind], TempPolygon[cur_ind + 1], TempPolygon[cur_ind + 2]) > 0) && (cur_ind + 2 != begin_ind))
                    {
                        if ((Intersect(begin_ind, cur_ind + 1, cur_ind + 2) == true) ||
                            (Geom2d.Square(TempPolygon[begin_ind], TempPolygon[begin_ind + 1], TempPolygon[cur_ind + 2]) < 0))
                        {
                            break;
                        }
                        ConvPolygons[CPH].Add(TempPolygon[cur_ind + 2]);
                        cur_ind++;
                    }
                }

                TempPolygon.RemoveRange(begin_ind, cur_ind);
                begin_ind++;
            }
        }
Esempio n. 4
0
        protected void UpdateSCS()
        {
            if (VertexCount == 3)
            {
                convexity         = 1;
                self_intersection = -1;
                square2           = Geom2d.Square(Vertexes[0], Vertexes[1], Vertexes[2]);
            }
            else
            if (VertexCount > 3)
            {
                double S = Geom2d.Square(Vertexes[VertexCount - 2], Vertexes[VertexCount - 1], Vertexes[0]);
                if (((S < 0) && (square2 > 0)) || ((S > 0) && (square2 < 0)))
                {
                    convexity = -1;
                }
                else
                if ((S == 0) && (square2 == 0))
                {
                    convexity = 0;
                }

                square2 += S;


                PointD O;
                for (int i = 1; i <= VertexCount - 3; i++)
                {
                    if (Geom2d.Intersection(Vertexes[i], Vertexes[i + 1], Vertexes[VertexCount - 1], Vertexes[0], out O) == 1)
                    {
                        self_intersection = 1;
                        break;
                    }
                }

                /*perimeter -= Geom2d.Distance(Vertexes[VertexCount - 1], Vertexes[0]);
                 * perimeter += Geom2d.Distance(Vertexes[VertexCount - 1], Vertexes[VertexCount]);
                 * perimeter += Geom2d.Distance(Vertexes[VertexCount], Vertexes[0]);*/
            }
        }