private double CaInterLSubIntegral(CPoint frfrcpt, CPoint frtocpt, CPoint tofrcpt, CPoint totocpt, CPoint StandardVectorCpt, double dbInterLSmallDis, double dblVerySamll)
        {
            CPoint newfrfrcpt = new CPoint(0, frfrcpt.X + StandardVectorCpt.X, frfrcpt.Y + StandardVectorCpt.Y);
            CPoint newfrtocpt = new CPoint(0, frtocpt.X + StandardVectorCpt.X, frtocpt.Y + StandardVectorCpt.Y);

            CEdge frcedge = new CEdge(newfrfrcpt, newfrtocpt);
            CEdge tocedge = new CEdge(tofrcpt, totocpt);

            frcedge.SetLength();
            tocedge.SetLength();


            if (CCmpMethods.CmpCEdgeCoord(frcedge, tocedge, true) == 0 ||
                (frcedge.dblLength == 0 && tocedge.dblLength == 0))  //为了应付刚开始时有重合的对应点
            {
                return(0);
            }


            double dblLength = frcedge.dblLength;

            if (frcedge.dblLength < tocedge.dblLength)
            {
                dblLength = tocedge.dblLength;
            }

            int    intSegmentNum = Convert.ToInt32(dblLength / dbInterLSmallDis) + 1;
            double frlength      = frcedge.dblLength / intSegmentNum;
            double tolength      = tocedge.dblLength / intSegmentNum;

            //梯形面积(因为所有的上底和下底都相同,因此可以先将各个梯形的高相加,再在循环外乘以高、除以2)
            double dbledgelength   = 0;
            double dblRatio        = 1 / Convert.ToDouble(intSegmentNum);
            double dblCurrentRatio = 0;

            for (int k = 0; k < intSegmentNum; k++)
            {
                double dblfrx = (1 - dblCurrentRatio) * newfrfrcpt.X + dblCurrentRatio * newfrtocpt.X;
                double dblfry = (1 - dblCurrentRatio) * newfrfrcpt.Y + dblCurrentRatio * newfrtocpt.Y;
                double dbltox = (1 - dblCurrentRatio) * tofrcpt.X + dblCurrentRatio * totocpt.X;
                double dbltoy = (1 - dblCurrentRatio) * tofrcpt.Y + dblCurrentRatio * totocpt.Y;

                dbledgelength   += CGeoFunc.CalDis(dblfrx, dblfry, dbltox, dbltoy);
                dblCurrentRatio += dblRatio;
            }

            double dbInterLSubIntegral = dbledgelength * (frlength + tolength) / 2;

            return(dbInterLSubIntegral);
        }
Beispiel #2
0
        //private void SgCplTraverse(CTriangulation pFrCtgl, List <CEdge > SgCEdgeLt, ref int intIndex)
        private CPolyline GenerateCorrSgCpl(CCptbCtgl pCptbCtgl, CPolyline SgCpl, SortedDictionary <CPoint, CPoint> pInterLSCptSD)
        {
            CTriangulation pFrCtgl     = pCptbCtgl.FrCtgl;
            CTriangulation pToCtgl     = pCptbCtgl.ToCtgl;
            var            AffineCptLt = new List <CPoint>(SgCpl.CptLt.Count);

            AffineCptLt.Add(CalFirstAffineCpt(pCptbCtgl, SgCpl.CptLt[0], pInterLSCptSD));   //the first vertex

            SgCpl.JudgeAndFormCEdgeLt();
            //CareCEdge is an edge that current edge may cross with current triangle
            //CareCEdgeLt has three edges at most
            var CareCEdgeLt = FindCareCEdgeLtForFirstCEdge(pFrCtgl, SgCpl.CEdgeLt[0], pInterLSCptSD);

            if (SgCpl.CEdgeLt.Count == 1 && CCmpMethods.CmpCEdgeCoord(CareCEdgeLt[0], SgCpl.CEdgeLt[0]) == 0)
            {
                //this is a special case where a single polyline has only one edge (SgCEdge),
                //at the same time, this edge is used by the combined triangulation
                var newCEdge = pToCtgl.HalfEdgeLt[CareCEdgeLt[0].indexID];
                AffineCptLt.Add(newCEdge.ToCpt);
                return(new CPolyline(SgCpl.ID, AffineCptLt));
            }


            int intEdgeCount = 0;
            var CurrentCEdge = SgCpl.CEdgeLt[intEdgeCount++];

            do
            {
                bool isFoundExit = false;  //whether this edge can go out current polygon (a triangle)
                foreach (var carecedge in CareCEdgeLt)
                {
                    var pIntersection = CurrentCEdge.IntersectWith(carecedge);

                    switch (pIntersection.enumIntersectionType)
                    {
                    case CEnumIntersectionType.NoNo:
                        break;

                    //this case is actually only for the fisrt vertex of a SgCpl,
                    //because for other intersections which coincide a triangulation node,
                    //we would not add the two neighbour edges in to CareCEdgeLt
                    case CEnumIntersectionType.FrFr:
                        CareCEdgeLt = GetCareCEdgeLtCptCoincident(carecedge.FrCpt, CurrentCEdge);
                        isFoundExit = true;
                        break;

                    //this case is actually only for the fisrt vertex of a SgCpl,
                    //because for other intersections which coincide a triangulation node,
                    //we would not add the two neighbour edges in to CareCEdgeLt
                    case CEnumIntersectionType.FrIn:
                        //this can happen, when the first SgCpt is on an triangle edge of FrCtgl
                        CareCEdgeLt = GetCareCEdgeLt(carecedge.cedgeTwin, false);
                        isFoundExit = true;
                        break;

                    //this case is actually only for the fisrt vertex of a SgCpl,
                    //because for other intersections which coincide a triangulation node,
                    //we would not add the two neighbour edges in to CareCEdgeLt
                    case CEnumIntersectionType.FrTo:
                        CareCEdgeLt = GetCareCEdgeLtCptCoincident(carecedge.ToCpt, CurrentCEdge);      //this can happen
                        isFoundExit = true;
                        break;

                    case CEnumIntersectionType.InFr:
                        AffineCptLt.Add(pToCtgl.CptLt[carecedge.FrCpt.indexID]);
                        CareCEdgeLt = GetCareCEdgeLtCptCoincident(carecedge.FrCpt, CurrentCEdge);
                        isFoundExit = true;
                        break;

                    case CEnumIntersectionType.InIn:
                        AffineCptLt.Add(ComputeAffineCptForInbetween(pToCtgl, pIntersection));
                        CareCEdgeLt = GetCareCEdgeLt(carecedge.cedgeTwin, false);
                        isFoundExit = true;
                        break;

                    case CEnumIntersectionType.InTo:
                        AffineCptLt.Add(pToCtgl.CptLt[carecedge.ToCpt.indexID]);
                        CareCEdgeLt = GetCareCEdgeLtCptCoincident(carecedge.ToCpt, CurrentCEdge);
                        isFoundExit = true;
                        break;

                    case CEnumIntersectionType.ToFr:       //come to the end of an edge
                        AffineCptLt.Add(pToCtgl.CptLt[carecedge.FrCpt.indexID]);
                        if (intEdgeCount < SgCpl.CEdgeLt.Count)
                        {
                            CurrentCEdge = SgCpl.CEdgeLt[intEdgeCount];
                            CareCEdgeLt  = GetCareCEdgeLtCptCoincident(carecedge.FrCpt, CurrentCEdge);
                        }
                        intEdgeCount++;
                        isFoundExit = true;
                        break;

                    case CEnumIntersectionType.ToIn:       //come to the end of an edge
                        AffineCptLt.Add(ComputeAffineCptForInbetween(pToCtgl, pIntersection));
                        if (intEdgeCount < SgCpl.CEdgeLt.Count)
                        {
                            CurrentCEdge = SgCpl.CEdgeLt[intEdgeCount];
                            CareCEdgeLt  = GetCareCEdgeLt(carecedge.cedgeTwin, false);
                        }
                        intEdgeCount++;
                        isFoundExit = true;
                        break;

                    case CEnumIntersectionType.ToTo:       //come to the end of an edge
                        AffineCptLt.Add(pToCtgl.CptLt[carecedge.ToCpt.indexID]);
                        if (intEdgeCount < SgCpl.CEdgeLt.Count)
                        {
                            CurrentCEdge = SgCpl.CEdgeLt[intEdgeCount];
                            CareCEdgeLt  = GetCareCEdgeLtCptCoincident(carecedge.ToCpt, CurrentCEdge);
                        }
                        intEdgeCount++;
                        isFoundExit = true;
                        break;

                    //maybe we can just ignore overlap, because if there is overlap, then there is also other cases
                    case CEnumIntersectionType.Overlap:
                        MessageBox.Show("we didn't consider Overlap when GenerateCorrSgCpl in:" + this.ToString() + ".cs   ");
                        break;

                    default:
                        break;
                    }

                    if (isFoundExit == true)
                    {
                        break;
                    }
                }

                if (isFoundExit == false)   //come to the end of an edge
                {
                    AffineCptLt.Add(CalAffineCpt(CurrentCEdge.ToCpt, CareCEdgeLt[0], pFrCtgl, pToCtgl));
                    if (intEdgeCount < SgCpl.CEdgeLt.Count)
                    {
                        CurrentCEdge = SgCpl.CEdgeLt[intEdgeCount];
                        CareCEdgeLt  = GetCareCEdgeLt(CareCEdgeLt[0], true);
                    }
                    intEdgeCount++;
                }
            } while (intEdgeCount <= SgCpl.CEdgeLt.Count);

            return(new CPolyline(SgCpl.ID, AffineCptLt));
        }