Ejemplo n.º 1
0
        private void Divide(GhostTriangle2D ghostTriangle)
        {
            Triangle2D triangle = ghostTriangle.ToTriangle(firstPolygon);

            Point2D point = (triangle.A + triangle.B.ToVector() + triangle.C.ToVector()) / 3;

            Polygon2DEditor polygonEditor = new Polygon2DEditor(firstPolygon);

            polygonEditor.AddInnerPoint(point);

            triangle = ghostTriangle.ToTriangle(secondPolygon);

            point = (triangle.A + triangle.B.ToVector() + triangle.C.ToVector()) / 3;

            polygonEditor = new Polygon2DEditor(secondPolygon);

            polygonEditor.AddInnerPoint(point);
        }
        private void AddInnerPoints(Polygon2DAdorner polygon)
        {
            for (int j = 0; j < this.ghostPoint.Count; j++)
            {
                for (int i = 0; i < polygon.internalSegments.Count; i++)
                {
                    int a = (int)(polygon.internalSegments[i].X);
                    int b = (int)(polygon.internalSegments[i].Y);

                    if (a == this.ghostPoint[j].FirstIndex && b == this.ghostPoint[j].LastIndex || a == this.ghostPoint[j].LastIndex && b == this.ghostPoint[j].FirstIndex)
                    {
                        Point2D point = null;
                        LineSegment2D lineSegment = null;

                        lineSegment = new LineSegment2D(polygon.polygon.GetPoint(a), polygon.polygon.GetPoint(b));

                        point = lineSegment.GetPoint(this.ghostPoint[j].LocalPosition);

                        Polygon2DEditor polygonEditor = new Polygon2DEditor(polygon.polygon);

                        polygonEditor.AddInnerPoint(point);

                        break;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private GhostTriangle2D Split(Polygon2D first, Polygon2D second, GhostTriangle2D ghostTriangle)
        {
            Triangle2D triangle = ghostTriangle.ToTriangle(first);
            LineSegment2D splitLine = Max(triangle.AB, triangle.BC, triangle.AC);
            int a = first.GetPointIndex(splitLine.FirstPoint);
            int b = first.GetPointIndex(splitLine.LastPoint);
            Point2D p1 = splitLine.MidPoint;
            splitLine = new LineSegment2D(second.GetPoint(a), second.GetPoint(b));
            Point2D p2 = splitLine.MidPoint;

            Polygon2DEditor polygonEditor = new Polygon2DEditor(first);
            polygonEditor.AddInnerPoint(p1);
            polygonEditor = new Polygon2DEditor(second);
            polygonEditor.AddInnerPoint(p2);

            return new GhostTriangle2D(a, b, first.PointCount - 1);
        }
Ejemplo n.º 4
0
        public void Fitting()
        {
            GhostWeb ghostWeb = new GhostWeb(this.sourcePolygon, this.ghostTriangles);

            Vector[] vectors = new Vector[this.sourcePolygon.PointCount];

            for (int i = 0; i < vectors.Length; i++)
            {
                vectors[i] = new Vector(vectors.Length);
                vectors[i][i] = 1;

                if (i < this.sourcePolygon.VertexCount || this.sourcePolygon.isOnEdge(this.sourcePolygon.GetPoint(i)))
                {
                    continue;
                }

                else
                {
                    vectors[i][i] = 0;
                    WebNode webNode = ghostWeb.webNodes[i];

                    while (webNode!= null)
                    {
                        vectors[i][i] ++;
                        vectors[i][webNode.firstIndex] = -1;
                        vectors[i][webNode.secondIndex] = -1;

                        webNode = webNode.Next;
                    }
                }
            }

            Vector valx = new Vector(this.sourcePolygon.PointCount);
            Vector valy = new Vector(this.sourcePolygon.PointCount);

            for (int i = 0; i < this.targetPolygon.VertexCount; i++)
            {
                valx[i] = this.targetPolygon.GetPoint(i).X;
                valy[i] = this.targetPolygon.GetPoint(i).Y;
            }

            for (int i = this.sourcePolygon.VertexCount; i <this.sourcePolygon.PointCount; i++)
            {
                Point2D point = this.sourcePolygon.GetPoint(i);
                if(this.sourcePolygon.isOnEdge(point))
                {

                    int x = this.sourcePolygon.OnEdge(point);
                    LineSegment2D line = this.sourcePolygon.GetEdge(x);

                    double pos = line.GetPosition(point);
                    line = this.targetPolygon.GetEdge(x);

                    Point2D newPoint = line.GetPoint(pos);

                    valx[i] = newPoint.X;
                    valy[i] = newPoint.Y;
                }
            }

            Matrix m = new Matrix(vectors).Translate();

            UpdateStatus(this, "Constructing...");

            LinearSystem lsx = new LinearSystem(new Matrix(m), valx);

            UpdateStatus(this, "Done");

            lsx.UpdateStatus += new Microsoft.VS.Akira.Triangulations.LinearSystem.ShowStatus(UpdateStatus);
            lsx.Gaussian(this.sourcePolygon.VertexCount);

            LinearSystem lsy = new LinearSystem(new Matrix(m), valy);
            lsy.UpdateStatus += new Microsoft.VS.Akira.Triangulations.LinearSystem.ShowStatus(UpdateStatus);
            lsy.Gaussian(this.sourcePolygon.VertexCount);

            Polygon2DEditor pe = new Polygon2DEditor(this.targetPolygon);

            UpdateStatus(this, "AddInner..");

            for (int i = this.sourcePolygon.VertexCount; i < this.sourcePolygon.PointCount; i++)
            {
                Point2D point = new Point2D(lsx.Value[i], lsy.Value[i]);
                pe.AddInnerPoint(point);
            }

            UpdateStatus(this, "Done");
        }