public static bool GetMaximumRotation_Assembly_ComposedPatterns(List <MyPatternOfComponents> listOfPatternOnThePath, MyCircumForPath pathObject, ref int i, ref int numOfPatterns, ref bool noStop, ref MyComposedPatternOfComponents outputComposedPattern, SldWorks SwApplication, ref StringBuilder fileOutput) { var listOfPatternsOfNew = new List <MyPatternOfComponents> { listOfPatternOnThePath[i] }; var lengthOfNew = 1; var exit = false; //Computation of the rotation angle: double[] planeNormal = { pathObject.circumplane.a, pathObject.circumplane.b, pathObject.circumplane.c }; var teta = FunctionsLC.FindAngle(listOfPatternOnThePath[0].patternCentroid, listOfPatternOnThePath[1].patternCentroid, pathObject.circumcenter); var axisDirection = Part.PartUtilities.GeometryAnalysis.establishAxisDirection(listOfPatternOnThePath[0].patternCentroid, listOfPatternOnThePath[1].patternCentroid, pathObject.circumcenter, planeNormal); while (i < (numOfPatterns - 1) && exit == false) { if (IsRotationTwoPatterns_Assembly(listOfPatternOnThePath[i], listOfPatternOnThePath[i + 1], teta, axisDirection, SwApplication, ref fileOutput)) { listOfPatternsOfNew.Add(listOfPatternOnThePath[i + 1]); lengthOfNew += 1; i++; } else { exit = true; noStop = false; i++; } } if (lengthOfNew > 1) { outputComposedPattern.ListOfMyPatternOfComponents = listOfPatternsOfNew; outputComposedPattern.pathOfMyComposedPatternOfComponents = pathObject; outputComposedPattern.typeOfMyComposedPatternOfComponents = "ROTATION"; outputComposedPattern.constStepOfMyComposedPatternOfComponents = listOfPatternsOfNew[0].patternCentroid.Distance( listOfPatternsOfNew[1].patternCentroid); return(true); } return(false); }
//Restituisce le equazioni cartesiane della circonferenza passante per V1, V2, V3 public static MyCircumForPath CircumPassingThrough(MyVertex V1, MyVertex V2, MyVertex V3, ref StringBuilder fileOutput, ModelDoc2 SwModel, SldWorks swApplication) { //The circumference does not exist if the 3 points lie on the same line or if 2 of them are coincident. if (V1.Lieonline(LinePassingThrough(V2, V3)) || V1.Equals(V2) || V1.Equals(V3) || V2.Equals(V3)) { MyCircumForPath OutputCircum = new MyCircumForPath(); return(OutputCircum); } else { MyPlane CircumPlane = PlanePassingThrough(V1, V2, V3); //There is a unique sphere passing through 4 points: we must arbitrarily choose a fourth point not lying on the V1-V2-V3 plane //So we choose the point resulting from adding the normal direction to a point lying on the V1-V2-V3 plane, for example V1 MyVertex V4 = new MyVertex(V1.x + CircumPlane.a * 10, V1.y + CircumPlane.b * 10, V1.z + CircumPlane.c * 10); //Vertex V4 = new Vertex(0, 0, 0); //if (SwModel != null) //{ // SwModel = swApplication.ActiveDoc; // SwModel.ClearSelection2(true); // SwModel.Insert3DSketch(); // SwModel.CreatePoint2(V1.x, V1.y, V1.z); // SwModel.InsertSketch(); // SwModel.CreatePoint2(V2.x, V2.y, V2.z); // SwModel.InsertSketch(); // SwModel.CreatePoint2(V3.x, V3.y, V3.z); // SwModel.InsertSketch(); // SwModel.CreatePoint2(V4.x, V4.y, V4.z); // SwModel.InsertSketch(); //} MySphere CircumSphere = SpherePassingThrough(V1, V2, V3, V4, ref fileOutput, SwModel); if (CircumSphere.centerSphere == null) { } else if (CircumSphere.centerSphere != null) { MyCircumForPath OutputCircum = new MyCircumForPath(CircumPlane, CircumSphere); return(OutputCircum); } } MyCircumForPath OutputCircumNull = new MyCircumForPath(); return(OutputCircumNull); }
//It detect the maximum symmetry relation in a set of MyRepeatedEntity, starting from index i of the list of MyRE public static bool GetMaximumRotation(List <MyRepeatedEntity> listOfREOnThePath, MyCircumForPath pathObject, ref int i, ref int numOfRE, ref bool noStop, ref MyPattern outputPattern, List <MyGroupingSurface> listOfInitialGroupingSurface) { //const string nameFile = "GetRotationalPatterns.txt"; //KLdebug.Print(" ", nameFile); //KLdebug.Print("NUOVO AVVIO DI RICERCA ROTAZIONE", nameFile); //KLdebug.Print(" ", nameFile); //var whatToWrite = ""; var listOfREOfNewMyPattern = new List <MyRepeatedEntity> { listOfREOnThePath[i] }; var lengthOfCurrentPath = 1; // = it represents the number of couples related by translation var exit = false; //Computation of the rotation angle: double[] planeNormal = { pathObject.circumplane.a, pathObject.circumplane.b, pathObject.circumplane.c }; var teta = FunctionsLC.FindAngle(listOfREOnThePath[0].centroid, listOfREOnThePath[1].centroid, pathObject.circumcenter); var axisDirection = establishAxisDirection(listOfREOnThePath[0].centroid, listOfREOnThePath[1].centroid, pathObject.circumcenter, planeNormal); //var SwModel = (ModelDoc2)SwApplication.ActiveDoc; //SwModel.ClearSelection2(true); //SwModel.Insert3DSketch(); //SwModel.CreatePoint2(pathObject.circumcenter.x, pathObject.circumcenter.y, pathObject.circumcenter.z); //SwModel.InsertSketch(); while (i < (numOfRE - 1) && exit == false) //fino alla penultima RE { //KLdebug.Print(" ", nameFile); //KLdebug.Print(" ", nameFile); //whatToWrite = string.Format(" Confronto {0}^ RE e la {1}^ RE: ", i, i + 1); //KLdebug.Print(whatToWrite, nameFile); if (IsRotationTwoRE(listOfREOnThePath[i], listOfREOnThePath[i + 1], teta, axisDirection, pathObject.circumcenter)) { listOfREOfNewMyPattern.Add(listOfREOnThePath[i + 1]); lengthOfCurrentPath += 1; //KLdebug.Print("Aggiunta " + (i + 1) + "-esima RE al MYPattern. lengthOfCurrentPath = " + lengthOfCurrentPath, nameFile); i++; } else { exit = true; noStop = false; //KLdebug.Print(" ", nameFile); //KLdebug.Print("------>>> Interruzione alla posizione: " + i, nameFile); //KLdebug.Print(" ", nameFile); i++; } } // KLdebug.Print(" ", nameFile); if (lengthOfCurrentPath > 1) { outputPattern.listOfMyREOfMyPattern = listOfREOfNewMyPattern; outputPattern.pathOfMyPattern = pathObject; var listOfGroupingSurfaceForThisPattern = findGroupingSurfacesForThisPattern(listOfInitialGroupingSurface, listOfREOfNewMyPattern, lengthOfCurrentPath); outputPattern.listOfGroupingSurfaces = listOfGroupingSurfaceForThisPattern; //KLdebug.Print("lengthOfCurrentPath = " + lengthOfCurrentPath, nameFile); outputPattern.typeOfMyPattern = "ROTATION"; outputPattern.constStepOfMyPattern = listOfREOfNewMyPattern[0].centroid.Distance(listOfREOfNewMyPattern[1].centroid); //KLdebug.Print("CREATO PATTERN Rotazionale circolare DI LUNGHEZZA = " + lengthOfCurrentPath, nameFile); outputPattern.angle = teta; return(true); } //KLdebug.Print("lengthOfCurrentPath = " + lengthOfCurrentPath, nameFile); //KLdebug.Print("IL PATTERN TRANS ha LUNGHEZZA NULLA, NON HO CREATO NIENTE.", nameFile); //KLdebug.Print(" ", nameFile); return(false); }
public static bool KLGetMaximumRotation_Assembly(List <MyRepeatedComponent> listOfComponentsOnThePath, MyCircumForPath pathObject, ref int i, ref int numOfComp, ref bool noStop, ref MyPatternOfComponents outputPattern) { //const string nameFile = "GetRotationalPatterns.txt"; //KLdebug.Print(" ", nameFile); //KLdebug.Print("NUOVO AVVIO DI RICERCA ROTAZIONE", nameFile); //KLdebug.Print(" ", nameFile); //var whatToWrite = ""; var listOfREOnThePath = new List <MyRepeatedEntity>(listOfComponentsOnThePath.Select(comp => comp.RepeatedEntity)); var listOfREOfNewMyPattern = new List <MyRepeatedEntity> { listOfREOnThePath[i] }; var listOfComponetsOfNewMyPattern = new List <MyRepeatedComponent> { listOfComponentsOnThePath[i] }; var lengthOfCurrentPath = 1; // = it represents the number of couples related by translation var exit = false; if (pathObject.circumplane == null) { exit = true; noStop = false; i++; return(false); } //Computation of the rotation angle: double[] planeNormal = { pathObject.circumplane.a, pathObject.circumplane.b, pathObject.circumplane.c }; var teta = FunctionsLC.FindAngle(listOfREOnThePath[0].centroid, listOfREOnThePath[1].centroid, pathObject.circumcenter); var axisDirection = Part.PartUtilities.GeometryAnalysis.establishAxisDirection(listOfREOnThePath[0].centroid, listOfREOnThePath[1].centroid, pathObject.circumcenter, planeNormal); while (i < (numOfComp - 1) && exit == false) //fino alla penultima RE { //KLdebug.Print(" ", nameFile); //KLdebug.Print(" ", nameFile); //whatToWrite = string.Format(" Confronto {0}^ RE e la {1}^ RE: ", i, i + 1); //KLdebug.Print(whatToWrite, nameFile); if (true) //if (Part.PartUtilities.GeometryAnalysis.IsRotationTwoRE(listOfREOnThePath[i], listOfREOnThePath[i + 1], teta, axisDirection, pathObject.circumcenter)) { listOfREOfNewMyPattern.Add(listOfREOnThePath[i + 1]); listOfComponetsOfNewMyPattern.Add(listOfComponentsOnThePath[i + 1]); lengthOfCurrentPath += 1; //KLdebug.Print("Aggiunta " + (i + 1) + "-esima RE al MYPattern. lengthOfCurrentPath = " + lengthOfCurrentPath, nameFile); i++; } else { exit = true; noStop = false; //KLdebug.Print(" ", nameFile); //KLdebug.Print("------>>> Interruzione alla posizione: " + i, nameFile); //KLdebug.Print(" ", nameFile); i++; } } // KLdebug.Print(" ", nameFile); if (lengthOfCurrentPath > 1) { outputPattern.listOfMyRCOfMyPattern = listOfComponetsOfNewMyPattern; outputPattern.listOfMyRCOfMyPattern = listOfComponentsOnThePath; outputPattern.pathOfMyPattern = pathObject; outputPattern.typeOfMyPattern = "ROTATION"; outputPattern.constStepOfMyPattern = listOfREOfNewMyPattern[0].centroid.Distance(listOfREOfNewMyPattern[1].centroid); //KLdebug.Print("CREATO PATTERN Rotazionale circolare DI LUNGHEZZA = " + lengthOfCurrentPath, nameFile); outputPattern.angle = teta; return(true); } //KLdebug.Print("lengthOfCurrentPath = " + lengthOfCurrentPath, nameFile); //KLdebug.Print("IL PATTERN TRANS ha LUNGHEZZA NULLA, NON HO CREATO NIENTE.", nameFile); //KLdebug.Print(" ", nameFile); return(false); //const string nameFile = "GetRotationalPatterns.txt"; //KLdebug.Print(" ", nameFile); //KLdebug.Print("NUOVO AVVIO DI RICERCA ROTAZIONE", nameFile); //KLdebug.Print(" ", nameFile); //var whatToWrite = ""; ////var newMyPattern = new MyPattern(); //var listOfCompOfNewMyPattern = new List<MyRepeatedComponent> { listOfComponentsOnThePath[i] }; //var lengthOfCurrentPath = 1; // = it represents the number of couples related by translation //var exit = false; ////Computation of the rotation angle: //double[] planeNormal = //{ // pathObject.circumplane.a, // pathObject.circumplane.b, // pathObject.circumplane.c //}; //var teta = FunctionsLC.FindAngle(listOfComponentsOnThePath[0].Origin, listOfComponentsOnThePath[1].Origin, // pathObject.circumcenter); //KLdebug.Print(" --->>> TETA = " + teta, nameFile); //var axisDirection = // BRepUtilities.GeometryAnalysis.establishAxisDirection(listOfComponentsOnThePath[0].Origin, // listOfComponentsOnThePath[1].Origin, // pathObject.circumcenter, planeNormal); //while (i < (numOfComp - 1) && exit == false) //fino alla penultima Comp //{ // KLdebug.Print(" ", nameFile); // KLdebug.Print(" ", nameFile); // whatToWrite = string.Format(" Confronto {0}^ COMP e la {1}^ COMP: ", i, i + 1); // KLdebug.Print(whatToWrite, nameFile); // KLdebug.PrintTransformMatrix(listOfComponentsOnThePath[i].Transform, nameFile, SwApplication); // KLdebug.PrintTransformMatrix(listOfComponentsOnThePath[i + 1].Transform, nameFile, SwApplication); // if (IsRotationTwoComp_Assembly(listOfComponentsOnThePath[i], listOfComponentsOnThePath[i + 1], teta, axisDirection)) // { // listOfCompOfNewMyPattern.Add(listOfComponentsOnThePath[i + 1]); // lengthOfCurrentPath += 1; // KLdebug.Print( // "Aggiunta " + (i + 1) + "-esima COMP al MYPattern. lengthOfCurrentPath = " + lengthOfCurrentPath, // nameFile); // i++; // } // else // { // exit = true; // noStop = false; // KLdebug.Print(" ", nameFile); // KLdebug.Print("------>>> Interruzione alla posizione: " + i, nameFile); // KLdebug.Print(" ", nameFile); // i++; // } //} //KLdebug.Print(" ", nameFile); //if (lengthOfCurrentPath > 1) //{ // outputPattern.listOfMyRCOfMyPattern = listOfCompOfNewMyPattern; // outputPattern.pathOfMyPattern = pathObject; // KLdebug.Print("lengthOfCurrentPath = " + lengthOfCurrentPath, nameFile); // outputPattern.typeOfMyPattern = "ROTATION"; // outputPattern.angle = teta; // KLdebug.Print("CREATO PATTERN Rotazionale circolare DI LUNGHEZZA = " + lengthOfCurrentPath, nameFile); // return true; //} //KLdebug.Print("lengthOfCurrentPath = " + lengthOfCurrentPath, nameFile); //KLdebug.Print("IL PATTERN TRANS ha LUNGHEZZA NULLA, NON HO CREATO NIENTE.", nameFile); //KLdebug.Print(" ", nameFile); //return false; }
//Crea il massimo path CIRCONFERENZA a partire dai 3 punti dati public static List <int> ThreePointsGivenPathsCircum(MyMatrAdj MatrAdjToSee, List <MyVertex> ListCentroid, List <int> ListOfExtremePoints, int Point1, int Point2, int Point3, ref StringBuilder fileOutput, ref bool ToleranceOk, out MyPathGeometricObject pathCurve, ModelDoc2 swModel = null, SldWorks swApplication = null) { List <int> Path = new List <int>(); Path.Add(Point1); Path.Add(Point2); Path.Add(Point3); MyCircumForPath CircumPath = FunctionsLC.CircumPassingThrough( ListCentroid[Point1], ListCentroid[Point2], ListCentroid[Point3], ref fileOutput, swModel, swApplication); //procedo nella direzione Point2-Point3 fileOutput.AppendLine("Point3: " + Point3); List <int> BranchesThird = MatrAdjToSee.matr.GetRow(Point3).Find(entry => entry == 1).ToList(); //cerco tra questi BranchesThird.Remove(Point2); //foreach (int ind in BranchesThird) //{ // fileOutput.AppendLine("\n branch del 3° punto " + Point3 + ": " + ind); //} int Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath)); while (Next != -1 && BranchesThird[Next] != Point1) // mi devo fermare anche quando completo la circonferenza, se non va all'infinito { // Check if the tolerance is too rough int NumOfFound = BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath)).Count; if (NumOfFound == 1) { //List<int> listafind = BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath)); //foreach (int ind in listafind) //{ // fileOutput.AppendLine("Branch candidato a proseguire il path (dovrebbe essere solo uno!): " + ind); //} //fileOutput.AppendLine("Next: " + Next); int NextInd = BranchesThird[Next]; //fileOutput.AppendLine("Nextind: " + NextInd); BranchesThird.Clear(); BranchesThird = MatrAdjToSee.matr.GetRow(NextInd).Find(entry => entry == 1).ToList(); //cerco tra questi BranchesThird.Remove(Path.Last()); //rimuovo dai branch trovati l'ultimo elemento che avevo aggiunto al path (in coda), perché se no tornerei indietro Path.Add(NextInd); //aggiungo in coda al path Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath)); } else { fileOutput.AppendLine("NumOfFound > 1 !!!!"); //End the execution in the higher levels ToleranceOk = false; pathCurve = null; return(Path); } } #region Check if I can invert the direction of expansion on not //se non ho ancora completato il giro (Next=-1) e Point1 non era un Extreme point, inverto la direzione procedendo verso Point2-Point1 if (Next == -1) { if (!(ListOfExtremePoints.Contains(Point1))) { fileOutput.AppendLine("non ho ancora completato il giro"); BranchesThird.Clear(); BranchesThird = MatrAdjToSee.matr.GetRow(Point1).Find(entry => entry == 1).ToList(); //cerco tra questi BranchesThird.Remove(Point2); Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath)); while (Next != -1) // qui sono sicura che che non completerò mai la crf, se no l'avrebbe già completata nell'altro while { // Check if the tolerance is too rough int NumOfFound = BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath)) .Count; if (NumOfFound == 1) { //List<int> listafind = BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath)); //foreach (int ind in listafind) //{ // fileOutput.AppendLine("Branch candidato a proseguire il path (dovrebbe essere solo uno!): " + ind); //} //fileOutput.AppendLine("Next: " + Next); int NextInd = BranchesThird[Next]; //fileOutput.AppendLine("Nextind: " + NextInd); Console.ReadLine(); BranchesThird.Clear(); BranchesThird = MatrAdjToSee.matr.GetRow(NextInd).Find(entry => entry == 1).ToList(); //cerco tra questi BranchesThird.Remove(Path[0]); //rimuovo dai branch trovati l'ultimo elemento che avevo aggiunto al path (in testa), perché se no tornerei indietro Path.Insert(0, NextInd); //aggiungo in testa al path Next = BranchesThird.FindIndex( ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath)); } else { fileOutput.AppendLine("NumOfFound > 1 !!!! ERRORE. "); //End the execution in the higher levels ToleranceOk = false; pathCurve = null; return(Path); } } } } else //si è usciti dal 1° while perché BranchesThird[Next] == Point1, cioè ho completato il giro { Path.Add(BranchesThird[Next]); //aggiungo Point1 al Path (faccio un ciclo chiuso) } #endregion fileOutput.AppendLine("\n Nuovo path circonferenza:"); foreach (int ind in Path) { fileOutput.AppendLine(" - " + ind); } pathCurve = CircumPath; if (CircumPath != null) { return(Path); } Path.Clear(); return(Path); } //fine ThreePointsGivenPathsCircum