Beispiel #1
0
        static CrossList CrossWithLine(xy A, xy B, CurveArray Array, EdgeLoop E)
        {
            xyArray xyArray = Array.getxyArray();

            if (xyArray[xyArray.Count - 1].dist(xyArray[0]) > 0.0001)   // 17.6 ausgeklammert?-----------
            {
                xyArray.Add(xyArray[0]);
            }
            CrossList CL = CrossWithLine(A, B, xyArray, E);

            for (int i = 0; i < CL.Count; i++)
            {
                Curve C = E[i].ParamCurve;

                CL[i].Param1 = Array.xyArrayIndexToCurveArrayIndex(CL[i].Param1);
                if (CL[i].Param1 == 4)
                {
                }
                int First  = (int)CL[i].Param1;
                int Second = First + 1;
                if (Second >= Array.Count)
                {
                    Second = 0;
                }
                CL[i].A = Array.Value(First);
                CL[i].B = Array.Value(Second);
            }


            return(CL);
        }
Beispiel #2
0
        /// <summary>
        /// Generate a CurveArray by eliminating all cross points of the given Array and inserting
        /// new curves.
        /// </summary>
        /// <returns>CurveArray</returns>
        public CurveArray ToNetWork()
        {
            CurveArray result = new CurveArray();
            CrossList  CL     = getCrossList(this, true);
            int        k      = 0;

            for (int i = 0; i < CL.Count; i++)
            {
                CrossItem CI = CL[i];
                while (k < Utils.trunc(CI.Param1))
                {
                    Curve C = this[k];
                    result.Add(C.Clone());
                    k++;
                }
                double From = 0;
                while (k == Utils.trunc(CI.Param1))
                {
                    double Param = CI.Param1;
                    Param = System.Math.Round(Param, 8);
                    if (System.Math.Abs(From - Param - k) > 0.00001)
                    {
                        Curve C = this[k].Clone();
                        C.Slice(From, Param - k);
                        result.Add(C);
                    }
                    From = CI.Param1 - k;
                    if ((i + 1 < CL.Count) && (Utils.trunc(CL[i + 1].Param1) == k))
                    {
                        i++;
                        CI = CL[i];
                    }
                    else
                    {
                        if (System.Math.Abs(System.Math.Round(From, 8) - 1) > 0.00001)
                        {
                            Curve C1 = this[k].Clone();

                            double F = System.Math.Round(From, 8);
                            C1.Slice(F, 1);
                            result.Add(C1);
                        }
                        break;
                    }
                }
                k++;
            }

            while (k < Count)
            {
                Curve C = this[k];
                result.Add(C.Clone());
                k++;
            }
            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Get a <see cref="CrossList"/>, which contains the crossing points with
        /// another curve?. The parameter param1 and param2 in <see cref="CrossItem"/> are converted to
        /// a curve parameter.
        /// </summary>
        /// <param name="Curve"></param>
        /// <returns></returns>
        public CrossList GetCrossList(Curve Curve)
        {
            xyArray xyArray1 = new xyArray(this.Resolution + 1);
            xyArray xyArray2 = new xyArray(Curve.Resolution + 1);

            this.ToArray(xyArray1, 0);
            Curve.ToArray(xyArray2, 0);
            CrossList Result = xyArray1.getCrossList(xyArray2, true);

            for (int i = 0; i < Result.Count; i++)
            {
                CrossItem C = Result[i];
                C.Param1 = C.Param1 / this.Resolution;
                C.Param2 = C.Param2 / Curve.Resolution;
            }
            return(Result);
        }
Beispiel #4
0
        /// <summary>
        /// Calucalates a <see cref="CrossList"/> for this CurveArray with an other <see cref="Loca"/>.
        /// The CrossItemparameter <see cref="CrossItem.Param1"/> is relative to this CurveArray.
        /// <br/>
        /// The parameter <see cref="CrossItem.Param2"/>  relative to the "value"-Loca.
        /// If (<see cref="CrossItem.Param2"/> greater Loca[0].Count the take id =<see cref="CrossItem.Param2"/> - Loca[0].count,
        /// If (<see cref="CrossItem.Param2"/> greater Loca[1].Count the take id =<see cref="CrossItem.Param2"/> - Loca[1].count,
        /// and so on.
        /// </summary>
        /// <param name="value">A Loca</param>
        /// <param name="TangentialPoints">Respect curves, who are tangential an intersection.</param>
        /// <returns>A CrossList</returns>
        public CrossList getCrossList(Loca value, bool TangentialPoints)
        {
            CrossList Result = new CrossList();
            int       ct     = 0;

            for (int i = 0; i < value.Count; i++)
            {
                CrossList CL = getCrossList(value[i], TangentialPoints);
                for (int j = 0; j < CL.Count; j++)
                {
                    CrossItem CI = CL[j];
                    CI.Param2 = CI.Param2 + ct;
                    Result.Add(CI);
                    CI.CrossList = CL;
                }
                ct += value[i].Count;
            }

            return(Result);
        }
Beispiel #5
0
        /// <summary>
        /// It`s the same as the overloaded method, but you can set, whether Tangential points
        /// should be taken or not.
        /// </summary>
        /// <param name="value">An other CurveArray</param>
        /// <param name="TangentialPoints">True, if the tangential points are taken</param>
        /// <returns>A Crosslist</returns>
        public CrossList getCrossList(CurveArray value, bool TangentialPoints)
        {
            ArrayList L1 = GetConnections();
            ArrayList L2 = value.GetConnections();

            int       StartJ;
            CrossList CL;
            CrossList Result = new CrossList();

            Result.AllowMultiCross = TangentialPoints;// for instant
            int AIndex = 0;

            for (int i = 0; i < L1.Count; i++)
            {
                CurveArray CA     = (CurveArray)L1[i];
                xyArray    A      = CA.getxyArray();
                int        BIndex = 0;
                StartJ = 0;
                for (int j = StartJ; j < L2.Count; j++)
                {
                    CurveArray CB = (CurveArray)L2[j];
                    xyArray    B  = CB.getxyArray();
                    CL = A.getCrossList(B, TangentialPoints);
                    for (int k = 0; k < CL.Count; k++)
                    {
                        CrossItem CI  = CL[k];
                        double    aID = CA.xyArrayIndexToCurveArrayIndex(CI.Param1);
                        double    bID = CB.xyArrayIndexToCurveArrayIndex(CI.Param2);



                        CI.Param1 = (float)AIndex + CA.xyArrayIndexToCurveArrayIndex(CI.Param1);
                        CI.Param2 = (float)BIndex + CB.xyArrayIndexToCurveArrayIndex(CI.Param2);
                        Curve  C1  = CA[Utils.trunc(aID)];
                        Curve  C2  = CB[Utils.trunc(bID)];
                        double Lam = CI.Param1 - Utils.trunc(CI.Param1);
                        double Mue = CI.Param2 - Utils.trunc(CI.Param2);

                        CI.Param1 = IndexOf(C1) + Lam;
                        CI.Param2 = value.IndexOf(C2) + Mue;
                        Mue       = CI.Param2 - Utils.trunc(CI.Param2);

                        Lam = CI.Param1 - Utils.trunc(CI.Param1);

                        if (C1.Cross(C2, Lam, Mue, out Lam, out Mue))
                        {
                            if ((Lam < 0) && ((System.Math.Abs(Lam) < 0.000001)))
                            {
                                Lam = 0;
                            }
                            if (System.Math.Abs(Lam - 1) < 0.00001)
                            {
                                Lam = 0.999999;
                            }
                            CI.Param1 = Utils.trunc(CI.Param1) + Lam;

                            if ((Mue < 0) && ((System.Math.Abs(Mue) < 0.000001)))
                            {
                                Mue = 0;
                            }
                            if (System.Math.Abs(Mue - 1) < 0.00001)
                            {
                                Mue = 0.999999;
                            }
                            CI.Param2 = Utils.trunc(CI.Param2) + Mue;
                        }

                        else
                        {
                            Lam = 0;
                            if (C1.Equals(C2))
                            {
                                Lam = 1;
                            }
                        }


                        if ((Utils.trunc(CI.Param1) < 0) && (System.Math.Abs(CI.Param1) < 0.00001))
                        {
                            CI.Param1 = 0;
                        }
                        if ((Utils.trunc(CI.Param2) < 0) && (System.Math.Abs(CI.Param2) < 0.00001))
                        {
                            CI.Param2 = 0;
                        }



                        //if (((Utils.trunc(System.Math.Round(CI.Param1,3)) !=System.Math.Round(CI.Param1,3)))
                        //    ||
                        //    ((Utils.trunc(System.Math.Round(CI.Param1,3)) !=System.Math.Round(CI.Param1,3))))
                        Result.Add(CI);
                    }
                    BIndex += CB.Count;
                }
                AIndex += CA.Count;
            }
            return(Result);
        }
Beispiel #6
0
        static List <CrossItem> CreateSortedParams(Face F1, Face F2)
        {
            //------ Erstelle Schnittgerade von F1 und F2---------------
            PlaneSurface S1      = F1.Surface as PlaneSurface;
            PlaneSurface S2      = F2.Surface as PlaneSurface;
            Curve3D      Curve3D = null;

            Curve3D = GetCrossCurve3D(F1, F2); // Schnittgerade der Ebenen
            if (Curve3D == null)
            {
                return(null); // Parallel
            }
            //-----------------------------------------------------------


            List <CrossItem> SortedParams = new List <CrossItem>();
            //---------- Schneide im Parameterraum Face1 mit Schnittgeraden
            Line       L2D = S1.To2dCurve(Curve3D) as Line; // Die Schnittgerade wird auf die Ebene Face1 Projiziert
            CurveArray Ca2 = new CurveArray();

            Ca2.Add(L2D);                 // und in den zweiten CurveArray gestellt

            Loca Loca = F1.ParamCurves;   // die ParamCurves dieser Ebene werden in die Loca gestellt

            double           GlobalIndex = 0;
            List <CrossItem> CrossList   = new List <CrossItem>();

            for (int i = 0; i < Loca.Count; i++)
            {
                CurveArray Ca = Loca[i];

                EdgeLoop  EL = F1.Bounds[i];
                CrossList CL = CrossWithLine(L2D.A, L2D.B, Ca, EL);
                for (int g = 0; g < CL.Count; g++)
                {
                    if (CL[g].Param1 == EL.Count)
                    {
                        CL[g].Param1 = 0;
                    }
                }
                if (CL.Count == 0)
                {
                    continue;
                }                                  // Offener Array oder kein schnittpunkt

                for (int k = 0; k < CL.Count; k++) // Schittpunke der geraden mit Face 1
                {
                    CL[k].Tag     = 1;
                    CL[k].Bound   = i;
                    CL[k].Param1 += GlobalIndex;

                    CL[k].Intern = Ca;
                    CL[k].Face   = F1;
                    if (!(
                            (CL[k].Border1 == BorderBehavior.BorderEnd) && (CL[k].CrossKind == -1)
                            ||
                            (CL[k].Border1 == BorderBehavior.BorderBegin) && (CL[k].CrossKind == 1)
                            ))
                    {
                        ToSortedParams(CrossList, CL[k]); // werden nach Param2 einsortiert
                    }
                }

                GlobalIndex += Loca[i].Count;
            }

            // Analog für Face 2
            // Analog für Face2
            //---------- Schneide um Parameterraum Face2 mit Schnittgeraden
            L2D = S2.To2dCurve(Curve3D) as Line; // Die Schnittgerade wird auf die Ebene Face2 Projiziert
            Ca2 = new CurveArray();
            Ca2.Add(L2D);                        // und in den zweiten CurveArray gestellt

            // die ParamCurves dieser Ebene werden in die Loca gestellt
            Loca = F2.ParamCurves;

            GlobalIndex = 0;

            for (int j = 0; j < Loca.Count; j++)
            {
                EdgeLoop   EL = F2.Bounds[j];
                CurveArray Ca = Loca[j];
                CrossList  CL = CrossWithLine(L2D.A, L2D.B, Ca, EL);
                for (int g = 0; g < CL.Count; g++)
                {
                    if (CL[g].Param1 == EL.Count)
                    {
                        CL[g].Param1 = 0;
                    }
                }
                if (CL.Count == 0)
                {
                    continue;
                }                                  // Offener Array oder kein schnittpunkt
                for (int k = 0; k < CL.Count; k++) // Schittpunke der geraden mit Face 2
                {
                    CL[k].Tag     = 2;
                    CL[k].Bound   = j;
                    CL[k].Param1 += GlobalIndex;
                    CL[k].Intern  = Ca;
                    CL[k].Face    = F2;
                    if (!(
                            (CL[k].Border1 == BorderBehavior.BorderEnd) && (CL[k].CrossKind == -1)
                            ||
                            (CL[k].Border1 == BorderBehavior.BorderBegin) && (CL[k].CrossKind == 1)
                            ))
                    {
                        ToSortedParams(CrossList, CL[k]); // werden nach Param1 einsortiert
                    }
                    else
                    {
                    }
                }

                GlobalIndex += Loca[j].Count;
            }
            if (CrossList.Count > 4)
            {
            }
            int Face1Status = 0;
            int Face2Status = 0;
            int id          = 0;

            while (id < CrossList.Count)
            {
                if ((int)CrossList[id].Tag == 1)
                {
                    Face1Status += CrossList[id].CrossKind;
                }
                if ((int)CrossList[id].Tag == 2)
                {
                    Face2Status += CrossList[id].CrossKind;
                }

                //if (id < CrossList.Count-1)
                if ((Face2Status == 0) && (Face1Status == 0))
                {
                    if (id > 0)
                    {
                        if ((int)CrossList[id - 1].Tag == (int)CrossList[id].Tag)
                        {
                            if (id + 1 < CrossList.Count)
                            {
                                if (System.Math.Abs(CrossList[id + 1].Param2 - CrossList[id].Param2) > 0.000001)
                                {
                                    CrossList.RemoveAt(id - 1);
                                    CrossList.RemoveAt(id - 1);
                                    id--;
                                }
                                else
                                {
                                    id++;
                                }
                            }
                        }
                        else
                        {
                            id++;
                        }
                    }
                }
                else
                {
                    id++;
                }
            }

            return(CrossList);
        }
Beispiel #7
0
        static CrossList CrossWithLine(xy A, xy B, xyArray Array, EdgeLoop E)
        {
            CrossList Result = new CrossList();
            double    Lam    = -1;
            double    Mue    = -1;

            _Array1 = Array;
            xy Last = Array[Array.Count - 1];

            for (int i = 0; i < Array.Count - 1; i++)
            {
                if (i < Array.Count - 1)
                {
                    if (Array[i].dist(Array[i + 1]) < LuckyEpsilon)
                    {
                        continue;
                    }
                }
                int Nexti = Succ(i);

                xy Next = Array[Nexti];
                if (!(TwoLines(A, B, Array[i], Next, ref Lam, ref Mue)))
                {
                    continue;
                }
                Lam = System.Math.Round(Lam, 8);
                Mue = System.Math.Round(Mue, 8);

                double D1  = Distance(Next, A, B);
                double D2  = Distance(Array[i], A, B);
                int    Prv = Prev(i);
                double D3  = Distance(Array[Prv], A, B);

                if ((System.Math.Abs(D1) < EdgeTolerance) &&
                    (System.Math.Abs(D2) < EdgeTolerance))
                {
                    Last = Array[i];
                    continue;
                }
                if ((System.Math.Abs(D1) >= EdgeTolerance) &&
                    (System.Math.Abs(D2) < EdgeTolerance))
                {
                    if ((System.Math.Abs(D3) < EdgeTolerance))
                    {
                        CrossItem CI = new CrossItem(i + LuckyEpsilon, Lam, -1);// FromBorder
                        if (D1 > 0)
                        {
                            CI.CrossKind = 1;
                        }
                        else
                        {
                            CI.CrossKind = -1;
                        }

                        CI.Border1 = BorderBehavior.BorderEnd;
                        Result.Add(CI);
                        continue;
                    }
                }
                if ((System.Math.Abs(D1) < EdgeTolerance) &&
                    (System.Math.Abs(D2) >= EdgeTolerance))
                {
                    int    succ         = Succ(Nexti);
                    double SuccDistance = System.Math.Abs(Distance(Array[succ], A, B));
                    if (SuccDistance <= EdgeTolerance)
                    {
                        // ToBorder
                        CrossItem CI = new CrossItem(i + (1 - LuckyEpsilon), Lam, -1);// ToBorder
                        CI.CrossKind = 1;
                        if (D2 < 0)
                        {
                            CI.CrossKind = 1;
                        }
                        else
                        {
                            CI.CrossKind = -1;
                        }
                        CI.Border1 = BorderBehavior.BorderBegin;
                        Result.Add(CI);
                        Last = Array[i];
                    }

                    continue;
                }


                if ((System.Math.Abs(D2) < EdgeTolerance) && (D1 * D3 < 0))
                {
                    // Mue ==0 Durchgehend
                    int kk = ToSide;
                    if (D1 < 0)
                    {
                        kk = -ToSide;
                    }


                    CrossItem CI = new CrossItem(i - Mue - 0.000000001, Lam, -1);
                    CI.CrossKind = 1;
                    if (D1 < 0)
                    {
                        CI.CrossKind = -1;
                    }

                    Result.Add(CI);
                    Last = Array[i];
                    continue;
                }
                else
                //else // neu------------------------------------------------------------
                if ((System.Math.Abs(D2) < EdgeTolerance) && (D1 * D3 > 0))
                {
                    if ((Mue >= -LuckyEpsilon) && ((Mue < 1 - LuckyEpsilon) &&
                                                   (Lam >= -LuckyEpsilon) && ((Lam <= 1 + LuckyEpsilon))))
                    {
                        xy     v1 = Array[i] - Array[Prv];
                        xy     v2 = Next - Array[i];
                        double kk = v1 & v2;
                        if (kk * D1 < 0)
                        {
                        }
                        //D1 = v1 & v2;
                        //D1 = -D1;


                        CrossItem CI = null;    // new CrossItem(i + Mue, Lam, -1);// ToBorder
                        if (D1 > 0)
                        {
                            CI = new CrossItem(i + Mue - LuckyEpsilon, Lam + LuckyEpsilon, -1);    // FromBorder
                        }
                        else
                        {
                            CI = new CrossItem(i + Mue - LuckyEpsilon, Lam - LuckyEpsilon, -1);    // FromBorder
                        }
                        if (D1 < 0)
                        {
                            CI.CrossKind = 1;
                        }
                        else
                        {
                            CI.CrossKind = -1;
                        }

                        CI.Border1 = BorderBehavior.BorderBegin;
                        Result.Add(CI);
                        if (D1 < 0)
                        {
                            CI = new CrossItem(i + Mue + LuckyEpsilon, Lam + LuckyEpsilon, -1);    // FromBorder
                        }
                        else
                        {
                            CI = new CrossItem(i + Mue + LuckyEpsilon, Lam - LuckyEpsilon, -1);    // FromBorder
                        }
                        if (D1 > 0)
                        {
                            CI.CrossKind = 1;
                        }
                        else
                        {
                            CI.CrossKind = -1;
                        }

                        CI.Border1 = BorderBehavior.BorderEnd;
                        Result.Add(CI);
                        continue;
                    }
                }
                if (D1 * D2 < 0)
                {
                    CrossItem CI = new CrossItem(i + Mue, Lam, -1);
                    CI.CrossKind = 1;
                    if (D1 < 0)
                    {
                        CI.CrossKind = -1;
                    }
                    Result.Add(CI);
                    Last = Array[i];
                    continue;
                }
            }

            return(Result);
        }