Exemple #1
0
        //Given 2 cylinder with corresponding radius and axis (MyLine) corresponding to the expected position for translation,
        //given the translation vector, it returns TRUE if the two base edges corresponds to the ones of the second cylinder,
        //it return FALSE otherwise.
        //For circles: a comparison of the centers is sufficient
        //For ellipses: a comparison of the centers, of the major and minor radius and of the axis (MyLine) is necessary
        public static bool CheckOfClosedEdgesCorrespondenceRefl(MyCylinder cylinderOfFirst, MyCylinder possibleCylinder, MyPlane candidateReflMyPlane)
        {
            const string nameFile = "GetReflectionalPattern.txt";

            var listOfCircleFirst   = cylinderOfFirst.listOfBaseCircle;
            var listOfCircleSecond  = new List <MyCircle>(possibleCylinder.listOfBaseCircle);
            var listOfEllipseFirst  = cylinderOfFirst.listOfBaseEllipse;
            var listOfEllipseSecond = new List <MyEllipse>(possibleCylinder.listOfBaseEllipse);

            int numOfCircleFirst   = listOfCircleFirst.Count;
            int numOfEllipseFirst  = listOfEllipseFirst.Count;
            int numOfCircleSecond  = listOfCircleSecond.Count;
            int numOfEllipseSecond = listOfEllipseSecond.Count;

            if (numOfCircleFirst == numOfCircleSecond && numOfEllipseFirst == numOfEllipseSecond)
            {
                if (numOfCircleFirst + numOfEllipseFirst == 0)  //cylinders with baseFace not planar
                {
                    return(true);
                }
                if (!CorrespondenceOfCirclesInCylinderRefl(candidateReflMyPlane, listOfCircleFirst, listOfCircleSecond))
                {
                    return(false);
                }

                if (!CorrespondenceOfEllipsesInCylinderRefl(candidateReflMyPlane, listOfEllipseFirst, listOfEllipseSecond))
                {
                    return(false);
                }

                return(true);
            }
            return(false);
        }
Exemple #2
0
        public static MyCylinder CreateMyCylinderFromFace(Surface faceSurface, Face2 face)
        {
            //OSSERVAZIONE: CI POTREBBERO ESSERE EDGE CHIUSI CHE NON AVERE CENTRO SULL'ASSE
            //AD ESEMPIO EDGE CHIUSI CHE SI CREANO INTERSECANDO UN CILINDRO CON UNA SFERA
            //"INFILATA" SULLA SUA SUPERFICIE LATERALE.
            //DI QUESTI EDGE CHIUSI NON ME NE PREOCCUPO PERCHE' SONO A CONTATTO CON ALTRE FORME
            //DI CUI SPERO DI AVER CONTROLLATO (NEL CONTROLLO DELLA GEOMETRIA) IL GIUSTO
            //POSIZIONAMENTO.


            double[] myCylinderParameters = faceSurface.CylinderParams;
            double[] myCylinderOrigin     =
            {
                (double)myCylinderParameters.GetValue(0), (double)myCylinderParameters.GetValue(1),
                (double)myCylinderParameters.GetValue(2)
            };
            double[] myCylinderAxis =
            {
                (double)myCylinderParameters.GetValue(3), (double)myCylinderParameters.GetValue(4),
                (double)myCylinderParameters.GetValue(5)
            };
            double myCylinderRadius = (double)myCylinderParameters.GetValue(6);

            var newMyCylinder = new MyCylinder(myCylinderOrigin, myCylinderAxis, myCylinderRadius);

            var faceEdges  = (Array)face.GetEdges();
            var numOfEdges = faceEdges.Length;

            int i = 0;
            var currentListOfBaseCircle  = new List <MyCircle>();
            var currentListOfBaseEllipse = new List <MyEllipse>();

            while (i < numOfEdges)
            {
                Edge  edge      = (Edge)faceEdges.GetValue(i);
                Curve curveEdge = edge.GetCurve();
                if (IsClosedEdge(edge))
                {
                    //is the closed edge a circle?
                    if (curveEdge.IsCircle())
                    {
                        double[] circleParam   = curveEdge.CircleParams;
                        var      newBaseCircle = new MyCircle(circleParam);
                        currentListOfBaseCircle.Add(newBaseCircle);
                    }
                    //is the closed edge an ellipse?
                    if (curveEdge.IsEllipse())
                    {
                        double[] ellipseParam   = curveEdge.GetEllipseParams();
                        var      newBaseEllipse = new MyEllipse(ellipseParam);
                        currentListOfBaseEllipse.Add(newBaseEllipse);
                    }
                }
                i++;
            }
            newMyCylinder.listOfBaseCircle  = currentListOfBaseCircle;
            newMyCylinder.listOfBaseEllipse = currentListOfBaseEllipse;
            return(newMyCylinder);
        }
        //Given 2 cylinder with corresponding radius and axis (MyLine) corresponding to the expected position for rotation,
        //given the rotation angle and the axis direction of rotation, it returns TRUE if the two base edges corresponds
        //to the ones of the second cylinder, it return FALSE otherwise.
        //For circles: a comparison of the centers is sufficient
        //For ellipses: a comparison of the centers, of the major and minor radius and of the axis (MyLine) is necessary
        public static bool CheckOfClosedEdgesCorrespondenceRot(MyCylinder cylinderOfFirst, MyCylinder possibleCylinder,
                                                               double teta, double[] axisDirection, double[] translationalVector)
        {
            const string nameFile = "GetRotationalPatterns.txt";

            var listOfCircleFirst   = cylinderOfFirst.listOfBaseCircle;
            var listOfCircleSecond  = new List <MyCircle>(possibleCylinder.listOfBaseCircle);
            var listOfEllipseFirst  = cylinderOfFirst.listOfBaseEllipse;
            var listOfEllipseSecond = new List <MyEllipse>(possibleCylinder.listOfBaseEllipse);

            int numOfCircleFirst   = listOfCircleFirst.Count;
            int numOfEllipseFirst  = listOfEllipseFirst.Count;
            int numOfCircleSecond  = listOfCircleSecond.Count;
            int numOfEllipseSecond = listOfEllipseSecond.Count;


            if (numOfCircleFirst == numOfCircleSecond && numOfEllipseFirst == numOfEllipseSecond)
            {
                if (numOfCircleFirst + numOfEllipseFirst == 0)  //cylinders with baseFace not planar
                {
                    return(true);
                }
                if (!CorrespondenceOfCirclesInCylinderRot(teta, axisDirection, translationalVector, listOfCircleFirst, listOfCircleSecond))
                {
                    return(false);
                }

                if (!CorrespondenceOfEllipsesInCylinderRot(teta, axisDirection, translationalVector, listOfEllipseFirst, listOfEllipseSecond))
                {
                    return(false);
                }

                return(true);
            }
            return(false);
        }
        public static bool MyEqualsSurface(Surface firstSurf, Surface secondSurf, SldWorks swApplWorks)
        {
            var answer = false;

            //var FirstSurface = (Surface)FirstFace.GetSurface();
            var typeOfFirstSurf = firstSurf.Identity();
            //var SecondSurface = (Surface)SecondFace.GetSurface();
            var typeOfSecondSurf = secondSurf.Identity();

            if (typeOfFirstSurf == typeOfSecondSurf)
            {
                if (firstSurf.IsPlane())
                {
                    var      firstPlaneParameters = firstSurf.PlaneParams;
                    double[] firstPlaneNormal     = { (double)firstPlaneParameters.GetValue(0), (double)firstPlaneParameters.GetValue(1), (double)firstPlaneParameters.GetValue(2) };
                    double[] firstPlanePoint      = { (double)firstPlaneParameters.GetValue(3), (double)firstPlaneParameters.GetValue(4), (double)firstPlaneParameters.GetValue(5) };

                    MyPlane firstPlane = new MyPlane(firstPlaneNormal, firstPlanePoint);

                    var      secondPlaneParameters = secondSurf.PlaneParams;
                    double[] secondPlaneNormal     = { (double)secondPlaneParameters.GetValue(0), (double)secondPlaneParameters.GetValue(1), (double)secondPlaneParameters.GetValue(2) };
                    double[] secondPlanePoint      = { (double)secondPlaneParameters.GetValue(3), (double)secondPlaneParameters.GetValue(4), (double)secondPlaneParameters.GetValue(5) };

                    MyPlane secondPlane = new MyPlane(secondPlaneNormal, secondPlanePoint);

                    //string fileNameBuildRepeatedEntity = "buildRepeatedEntity.txt";
                    //string whatToWrite = string.Format("Primo piano: a {0}, b {1}, c {2}, d {3}", firstPlane.a, firstPlane.b, firstPlane.c, firstPlane.d);
                    //KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity);
                    //whatToWrite = string.Format("Secondo piano: a {0}, b {1}, c {2}, d {3}", secondPlane.a, secondPlane.b, secondPlane.c, secondPlane.d);
                    //KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity);

                    if (firstPlane.Equals(secondPlane))
                    {
                        answer = true;
                    }
                }

                if (firstSurf.IsSphere())
                {
                    var      firstSphereParameters = firstSurf.SphereParams;
                    double[] firstSphereCenter     = { (double)firstSphereParameters.GetValue(0), (double)firstSphereParameters.GetValue(1), (double)firstSphereParameters.GetValue(2) };
                    double   firstSphereRay        = (double)firstSphereParameters.GetValue(3);

                    var firstSphere = new MySphere(firstSphereCenter, firstSphereRay);

                    var      secondSphereParameters = secondSurf.SphereParams;
                    double[] secondSphereCenter     = { (double)secondSphereParameters.GetValue(0), (double)secondSphereParameters.GetValue(1), (double)secondSphereParameters.GetValue(2) };
                    double   secondSphereRay        = (double)secondSphereParameters.GetValue(3);

                    var secondSphere = new MySphere(secondSphereCenter, secondSphereRay);

                    if (firstSphere.Equals(secondSphere))
                    {
                        answer = true;
                    }
                }

                if (firstSurf.IsCone())
                {
                    var firstConeParameters = firstSurf.ConeParams;
                    swApplWorks.SendMsgToUser("lunghezza vettore paramentri: " + firstConeParameters.GetValue(0));
                    swApplWorks.SendMsgToUser("lunghezza vettore paramentri: " + firstConeParameters.GetValue(1));
                    swApplWorks.SendMsgToUser("lunghezza vettore paramentri: " + firstConeParameters.GetValue(2));
                    swApplWorks.SendMsgToUser("lunghezza vettore paramentri: " + firstConeParameters.GetValue(3));
                    swApplWorks.SendMsgToUser("lunghezza vettore paramentri: " + firstConeParameters.GetValue(4));
                    swApplWorks.SendMsgToUser("lunghezza vettore paramentri: " + firstConeParameters.GetValue(5));
                    swApplWorks.SendMsgToUser("lunghezza vettore paramentri: " + firstConeParameters.GetValue(6));
                    swApplWorks.SendMsgToUser("lunghezza vettore paramentri: " + firstConeParameters.GetValue(7));
                    swApplWorks.SendMsgToUser("lunghezza vettore paramentri: " + firstConeParameters.GetValue(8));


                    double[] firstConeOrigin    = { (double)firstConeParameters.GetValue(0), (double)firstConeParameters.GetValue(1), (double)firstConeParameters.GetValue(2) };
                    double[] firstConeAxis      = { (double)firstConeParameters.GetValue(3), (double)firstConeParameters.GetValue(4), (double)firstConeParameters.GetValue(5) };
                    double   firstConeHalfAngle = (double)firstConeParameters.GetValue(8);

                    var firstCone = new MyCone(firstConeOrigin, firstConeAxis, firstConeHalfAngle);

                    var      secondConeParameters = secondSurf.ConeParams;
                    double[] secondConeOrigin     = { (double)secondConeParameters.GetValue(0), (double)secondConeParameters.GetValue(1), (double)secondConeParameters.GetValue(2) };
                    double[] secondConeAxis       = { (double)secondConeParameters.GetValue(3), (double)secondConeParameters.GetValue(4), (double)secondConeParameters.GetValue(5) };
                    double   secondConeHalfAngle  = (double)secondConeParameters.GetValue(8);

                    var secondCone = new MyCone(secondConeOrigin, secondConeAxis, secondConeHalfAngle);

                    if (firstCone.Equals(secondCone))
                    {
                        // L'EQUALS DEL CONO NON E' PROPRIO GIUSTO.
                        answer = true;
                    }
                }

                if (firstSurf.IsCylinder())
                {
                    double[] firstCylinderParameters = firstSurf.CylinderParams;
                    double[] firstCylinderOrigin     = { (double)firstCylinderParameters.GetValue(0), (double)firstCylinderParameters.GetValue(1), (double)firstCylinderParameters.GetValue(2) };
                    double[] firstCylinderAxis       = { (double)firstCylinderParameters.GetValue(3), (double)firstCylinderParameters.GetValue(4), (double)firstCylinderParameters.GetValue(5) };
                    double   firstCylinderRadius     = (double)firstCylinderParameters.GetValue(6);

                    var firstCylinder = new MyCylinder(firstCylinderOrigin, firstCylinderAxis, firstCylinderRadius);

                    double[] secondCylinderParameters = secondSurf.CylinderParams;
                    double[] secondCylinderOrigin     = { (double)secondCylinderParameters.GetValue(0), (double)secondCylinderParameters.GetValue(1), (double)secondCylinderParameters.GetValue(2) };
                    double[] secondCylinderAxis       = { (double)secondCylinderParameters.GetValue(3), (double)secondCylinderParameters.GetValue(4), (double)secondCylinderParameters.GetValue(5) };
                    double   secondCylinderRadius     = (double)secondCylinderParameters.GetValue(6);

                    var secondCylinder = new MyCylinder(secondCylinderOrigin, secondCylinderAxis, secondCylinderRadius);

                    if (firstCylinder.Equals(secondCylinder))
                    {
                        // CONTROLLARE L'EQUALS DEL CILINDRO
                        answer = true;
                    }
                }

                if (firstSurf.IsTorus())
                {
                    var      firstTorusParameters  = firstSurf.TorusParams;
                    double[] firstTorusCenter      = { (double)firstTorusParameters.GetValue(0), (double)firstTorusParameters.GetValue(1), (double)firstTorusParameters.GetValue(2) };
                    double[] firstTorusAxis        = { (double)firstTorusParameters.GetValue(3), (double)firstTorusParameters.GetValue(4), (double)firstTorusParameters.GetValue(5) };
                    double   firstTorusMajorRadius = (double)firstTorusParameters.GetValue(6);
                    double   firstTorusMinorRadius = (double)firstTorusParameters.GetValue(7);

                    var firstTorus = new MyTorus(firstTorusCenter, firstTorusAxis, firstTorusMajorRadius, firstTorusMinorRadius);

                    var      secondTorusParameters  = secondSurf.TorusParams;
                    double[] secondTorusCenter      = { (double)secondTorusParameters.GetValue(0), (double)secondTorusParameters.GetValue(1), (double)secondTorusParameters.GetValue(2) };
                    double[] secondTorusAxis        = { (double)secondTorusParameters.GetValue(3), (double)secondTorusParameters.GetValue(4), (double)secondTorusParameters.GetValue(5) };
                    double   secondTorusMajorRadius = (double)secondTorusParameters.GetValue(6);
                    double   secondTorusMinorRadius = (double)secondTorusParameters.GetValue(7);

                    var secondTorus = new MyTorus(secondTorusCenter, secondTorusAxis, secondTorusMajorRadius, secondTorusMinorRadius);

                    if (firstTorus.Equals(secondTorus))
                    {
                        // CONTROLLARE L'EQUALS DEL TORO
                        answer = true;
                    }
                }
            }
            else
            {
                answer = false;
            }

            return(answer);
        }
Exemple #5
0
        public static MyCylinder KLCreateMyCylinderFromFace(Surface faceSurface, Face2 face, double[,] transformationMatrix)
        {
            //OSSERVAZIONE: CI POTREBBERO ESSERE EDGE CHIUSI CHE NON AVERE CENTRO SULL'ASSE
            //AD ESEMPIO EDGE CHIUSI CHE SI CREANO INTERSECANDO UN CILINDRO CON UNA SFERA
            //"INFILATA" SULLA SUA SUPERFICIE LATERALE.
            //DI QUESTI EDGE CHIUSI NON ME NE PREOCCUPO PERCHE' SONO A CONTATTO CON ALTRE FORME
            //DI CUI SPERO DI AVER CONTROLLATO (NEL CONTROLLO DELLA GEOMETRIA) IL GIUSTO
            //POSIZIONAMENTO.

            //KLdebug.Print("FACCIA CILINDRICA", "buildRepeatedEntity.txt");
            //KLdebug.Print(" ", "buildRepeatedEntity.txt");

            double[] myCylinderParameters = faceSurface.CylinderParams;
            double[] myCylinderOrigin     =
            {
                (double)myCylinderParameters.GetValue(0), (double)myCylinderParameters.GetValue(1),
                (double)myCylinderParameters.GetValue(2)
            };
            double[] myCylinderAxis =
            {
                (double)myCylinderParameters.GetValue(3), (double)myCylinderParameters.GetValue(4),
                (double)myCylinderParameters.GetValue(5)
            };
            double myCylinderRadius = (double)myCylinderParameters.GetValue(6);

            if (transformationMatrix != null)
            {
                double[] myCylinderOriginAffine = { (double)myCylinderOrigin.GetValue(0), (double)myCylinderOrigin.GetValue(1), (double)myCylinderOrigin.GetValue(2), 1 };
                double[] myCylinderAxisAffine   = { (double)myCylinderAxis.GetValue(0), (double)myCylinderAxis.GetValue(1), (double)myCylinderAxis.GetValue(2), 1 };

                var newMyCylinderOrigin = Matrix.Multiply(transformationMatrix, myCylinderOriginAffine);
                var newMyCylinderAxis   = Matrix.Multiply(transformationMatrix, myCylinderAxisAffine);

                myCylinderOrigin.SetValue((double)newMyCylinderOrigin.GetValue(0), 0);
                myCylinderOrigin.SetValue((double)newMyCylinderOrigin.GetValue(1), 1);
                myCylinderOrigin.SetValue((double)newMyCylinderOrigin.GetValue(2), 2);

                //myCylinderAxis.SetValue((double)newMyCylinderAxis.GetValue(0), 0);
                //myCylinderAxis.SetValue((double)newMyCylinderAxis.GetValue(1), 1);
                //myCylinderAxis.SetValue((double)newMyCylinderAxis.GetValue(2), 2);
            }

            var newMyCylinder = new MyCylinder(myCylinderOrigin, myCylinderAxis, myCylinderRadius);

            var faceEdges  = (Array)face.GetEdges();
            var numOfEdges = faceEdges.Length;

            int i = 0;
            var currentListOfBaseCircle  = new List <MyCircle>();
            var currentListOfBaseEllipse = new List <MyEllipse>();

            while (i < numOfEdges)
            {
                Edge  edge      = (Edge)faceEdges.GetValue(i);
                Curve curveEdge = edge.GetCurve();
                if (IsClosedEdge(edge))
                {
                    //KLdebug.Print("trovato edge chiuso:", "buildRepeatedEntity.txt");


                    //is the closed edge a circle?
                    if (curveEdge.IsCircle())
                    {
                        double[] circleParam = curveEdge.CircleParams;
                        if (transformationMatrix != null)
                        {
                            double[] circleCenterAffine = { (double)circleParam.GetValue(0), (double)circleParam.GetValue(1), (double)circleParam.GetValue(2), 1 };

                            var newMyCircleOrigin = Matrix.Multiply(transformationMatrix, circleCenterAffine);

                            circleParam.SetValue((double)newMyCircleOrigin.GetValue(0), 0);
                            circleParam.SetValue((double)newMyCircleOrigin.GetValue(1), 1);
                            circleParam.SetValue((double)newMyCircleOrigin.GetValue(2), 2);
                        }
                        var newBaseCircle = new MyCircle(circleParam);
                        currentListOfBaseCircle.Add(newBaseCircle);
                    }
                    //is the closed edge an ellipse?
                    if (curveEdge.IsEllipse())
                    {
                        double[] ellipseParam = curveEdge.GetEllipseParams();

                        if (transformationMatrix != null)
                        {
                            double[] circleCenterAffine = { (double)ellipseParam.GetValue(0), (double)ellipseParam.GetValue(1), (double)ellipseParam.GetValue(2), 1 };

                            var newMyCircleOrigin = Matrix.Multiply(transformationMatrix, circleCenterAffine);

                            ellipseParam.SetValue((double)newMyCircleOrigin.GetValue(0), 0);
                            ellipseParam.SetValue((double)newMyCircleOrigin.GetValue(1), 1);
                            ellipseParam.SetValue((double)newMyCircleOrigin.GetValue(2), 2);
                        }

                        var newBaseEllipse = new MyEllipse(ellipseParam);
                        currentListOfBaseEllipse.Add(newBaseEllipse);
                    }
                }
                i++;
            }
            newMyCylinder.listOfBaseCircle  = currentListOfBaseCircle;
            newMyCylinder.listOfBaseEllipse = currentListOfBaseEllipse;
            return(newMyCylinder);
        }
        public static bool CylinderOfFirstAtPosition_i_IsOkRotation(MyRepeatedEntity firstMyRepeatedEntity,
                                                                    MyRepeatedEntity secondMyRepeatedEntity, double teta, double[] axisDirection,
                                                                    double[] translationalVector, MyCylinder cylinderOfFirst, ref int i)
        {
            const string nameFile  = "GetRotationalPatterns.txt";
            var          tolerance = Math.Pow(10, -5);

            //The axis of the second MyRepeatedEntity should have the same axis direction and
            //should pass through the rotated Origin of the cylinderOfFirst
            double[] originOfFirst = cylinderOfFirst.originCylinder;
            //var whatToWrite = string.Format("Centroid of first: ({0},{1},{2})", firstMyRepeatedEntity.centroid.x, firstMyRepeatedEntity.centroid.y, firstMyRepeatedEntity.centroid.z);
            //KLdebug.Print(whatToWrite, nameFile);
            //whatToWrite = string.Format("Centroid of first: ({0},{1},{2})", secondMyRepeatedEntity.centroid.x, secondMyRepeatedEntity.centroid.y, secondMyRepeatedEntity.centroid.z);
            //KLdebug.Print(whatToWrite, nameFile);

            double[] originOfFirstTranslated = { originOfFirst[0] + translationalVector[0],
                                                 originOfFirst[1] + translationalVector[1],
                                                 originOfFirst[2] + translationalVector[2] };
            var      originOfFirstTranslatedMyVertex = new MyVertex(originOfFirstTranslated[0], originOfFirstTranslated[1], originOfFirstTranslated[2]);

            var pointOnAxisTranslatedMyVertex = originOfFirstTranslatedMyVertex.Rotate(teta, axisDirection);

            double[] pointOnAxis = { pointOnAxisTranslatedMyVertex.x - translationalVector[0],
                                     pointOnAxisTranslatedMyVertex.y - translationalVector[1],
                                     pointOnAxisTranslatedMyVertex.z - translationalVector[2] };
            //whatToWrite = string.Format("Point on axis: ({0},{1},{2})", pointOnAxis[0], pointOnAxis[1], pointOnAxis[2]);
            //KLdebug.Print(whatToWrite, nameFile);

            var firstAxisDirectionMyVertex = new MyVertex(cylinderOfFirst.axisDirectionCylinder[0],
                                                          cylinderOfFirst.axisDirectionCylinder[1], cylinderOfFirst.axisDirectionCylinder[2]);
            var rotatedFirstAxisDirectionMyVertex = firstAxisDirectionMyVertex.Rotate(teta, axisDirection);

            double[] rotatedFirstAxisDirection =
            {
                rotatedFirstAxisDirectionMyVertex.x,
                rotatedFirstAxisDirectionMyVertex.y, rotatedFirstAxisDirectionMyVertex.z
            };

            var axisToFind = FunctionsLC.ConvertPointPlusDirectionInMyLine(pointOnAxis,
                                                                           rotatedFirstAxisDirection);
            var indOfFound =
                secondMyRepeatedEntity.listOfCylindricalSurfaces.FindIndex(
                    cyl => cyl.axisCylinder.Equals(axisToFind));

            if (indOfFound != -1)
            {
                var listOfPossibleCylinders =
                    secondMyRepeatedEntity.listOfCylindricalSurfaces.FindAll(
                        cyl => cyl.axisCylinder.Equals(axisToFind));
                var numOfPossibleCylinders = listOfPossibleCylinders.Count;

                //If I find cylinders with right axis line, I check the radius correspondence,
                //the center of bases correspondence.
                //For elliptical bases I make a further control on radius and direction axis.
                var notFound = true;
                int j        = 0;
                while (notFound && j < numOfPossibleCylinders)
                {
                    var possibleCylinder = listOfPossibleCylinders[j];
                    if (Math.Abs(cylinderOfFirst.radiusCylinder - possibleCylinder.radiusCylinder) < tolerance)
                    {
                        if (CheckOfClosedEdgesCorrespondenceRot(cylinderOfFirst, possibleCylinder,
                                                                teta, axisDirection, translationalVector))
                        {
                            notFound = false;
                        }
                    }
                    j++;
                }
                if (notFound)
                {
                    return(false);
                }

                //if the previous cylinder is ok, i pass to the next cylinder:
                i++;
            }
            else
            {
                return(false);
            }
            return(true);
        }
Exemple #7
0
        public static bool CylinderOfFirstAtPosition_i_IsOkReflection(MyRepeatedEntity firstMyRepeatedEntity,
                                                                      MyRepeatedEntity secondMyRepeatedEntity, MyPlane candidateReflMyPlane, MyCylinder cylinderOfFirst, ref int i)
        {
            const string nameFile  = "GetReflectionalPattern.txt";
            var          tolerance = Math.Pow(10, -5);

            //I compute the distance vector v between the centroidOfFirst and the Origin of the cylinderOfFirst (which pass through the axis)
            //The axis of the second MyRepeatedEntity should have the same axis direction and
            //should pass through the point = centroidOfSecond + v
            double[] originOfFirst         = cylinderOfFirst.originCylinder;
            var      originOfFirstMyVertex = new MyVertex(originOfFirst[0], originOfFirst[1], originOfFirst[2]);

            var pointOnAxisMyVertex = originOfFirstMyVertex.Reflect(candidateReflMyPlane);

            double[] pointOnAxis = { pointOnAxisMyVertex.x, pointOnAxisMyVertex.y, pointOnAxisMyVertex.z };

            var reflectedDirectionOfAxis = ReflectNormal(cylinderOfFirst.axisDirectionCylinder, candidateReflMyPlane);

            var axisToFind = FunctionsLC.ConvertPointPlusDirectionInMyLine(pointOnAxis,
                                                                           reflectedDirectionOfAxis);
            var indOfFound =
                secondMyRepeatedEntity.listOfCylindricalSurfaces.FindIndex(
                    cyl => cyl.axisCylinder.Equals(axisToFind));

            if (indOfFound != -1)
            {
                var listOfPossibleCylinders =
                    secondMyRepeatedEntity.listOfCylindricalSurfaces.FindAll(
                        cyl => cyl.axisCylinder.Equals(axisToFind));
                var numOfPossibleCylinders = listOfPossibleCylinders.Count;

                //If I find cylinders with right axis line, I check the radius correspondence,
                //the center of bases correspondence.
                //For elliptical bases I make a further control on radius and direction axis.
                var notFound = true;
                int j        = 0;
                while (notFound && j < numOfPossibleCylinders)
                {
                    var possibleCylinder = listOfPossibleCylinders[j];
                    if (Math.Abs(cylinderOfFirst.radiusCylinder - possibleCylinder.radiusCylinder) < tolerance)
                    {
                        if (CheckOfClosedEdgesCorrespondenceRefl(cylinderOfFirst, possibleCylinder,
                                                                 candidateReflMyPlane))
                        {
                            notFound = false;
                        }
                    }
                    j++;
                }
                if (notFound)
                {
                    return(false);
                }

                //if the previous cylinder is ok, i pass to the next cylinder:
                i++;
            }
            else
            {
                return(false);
            }
            return(true);
        }
Exemple #8
0
        //Given 2 cylinder with corresponding radius and axis (MyLine) corresponding to the expected position for translation,
        //given the translation vector, it returns TRUE if the two base edges corresponds to the ones of the second cylinder,
        //it return FALSE otherwise.
        //For circles: a comparison of the centers is sufficient
        //For ellipses: a comparison of the centers, of the major and minor radius and of the axis (MyLine) is necessary
        public static bool CheckOfClosedEdgesCorrespondenceTransl(MyCylinder cylinderOfFirst, MyCylinder possibleCylinder, double[] candidateTranslationArray)
        {
            const string nameFile = "GetTranslationalPatterns.txt";

            var listOfCircleFirst   = cylinderOfFirst.listOfBaseCircle;
            var listOfCircleSecond  = new List <MyCircle>(possibleCylinder.listOfBaseCircle);
            var listOfEllipseFirst  = cylinderOfFirst.listOfBaseEllipse;
            var listOfEllipseSecond = new List <MyEllipse>(possibleCylinder.listOfBaseEllipse);

            int numOfCircleFirst   = listOfCircleFirst.Count;
            int numOfEllipseFirst  = listOfEllipseFirst.Count;
            int numOfCircleSecond  = listOfCircleSecond.Count;
            int numOfEllipseSecond = listOfEllipseSecond.Count;

            if (numOfCircleFirst == numOfCircleSecond && numOfEllipseFirst == numOfEllipseSecond)
            {
                if (numOfCircleFirst + numOfEllipseFirst == 0)  //cylinders with baseFace not planar
                {
                    return(true);
                }
                if (!CorrespondenceOfCirclesInCylinderTransl(candidateTranslationArray, listOfCircleFirst, listOfCircleSecond))
                {
                    return(false);
                }

                if (!CorrespondenceOfEllipsesInCylinderTransl(candidateTranslationArray, listOfEllipseFirst, listOfEllipseSecond))
                {
                    return(false);
                }

                return(true);
            }
            return(false);

            #region prova
            //bool firstCenterOk = false;
            //if (cylinderOfFirst.firstBaseCurve.Identity() == possibleCylinder.firstBaseCurve.Identity())
            //{
            //    if (cylinderOfFirst.firstBaseCurve.IsCircle())
            //    {
            //        double[] firstCircleParam = cylinderOfFirst.firstBaseCurve.CircleParams;
            //        var firstCenter = new MyVertex(firstCircleParam[0], firstCircleParam[1], firstCircleParam[2]);

            //        double[] secondCircleParam = possibleCylinder.firstBaseCurve.CircleParams;
            //        var secondCenter = new MyVertex(secondCircleParam[0], secondCircleParam[1], secondCircleParam[2]);

            //        firstCenterOk = secondCenter.IsTranslationOf(firstCenter, candidateTranslationArray);

            //    }
            //    else
            //    {
            //        double[] firstEllipseParam = cylinderOfFirst.firstBaseCurve.GetEllipseParams();
            //        var firstCenter = new MyVertex(firstEllipseParam[0], firstEllipseParam[1], firstEllipseParam[2]);
            //        var firstMajorRad = firstEllipseParam[3];
            //        double[] firstMajorRadAxis = { firstEllipseParam[4], firstEllipseParam[5], firstEllipseParam[6] };
            //        var firstMinorRad = firstEllipseParam[7];
            //        double[] firstMinorRadAxis = { firstEllipseParam[8], firstEllipseParam[9], firstEllipseParam[10] };

            //        double[] secondEllipseParam = possibleCylinder.secondBaseCurve.GetEllipseParams();
            //        var secondCenter = new MyVertex(secondEllipseParam[0], secondEllipseParam[1], secondEllipseParam[2]);
            //        var secondMajorRad = secondEllipseParam[3];
            //        double[] secondMajorRadAxis = { secondEllipseParam[4], secondEllipseParam[5], secondEllipseParam[6] };
            //        var secondMinorRad = secondEllipseParam[7];
            //        double[] secondMinorRadAxis = { secondEllipseParam[8], secondEllipseParam[9], secondEllipseParam[10] };

            //        firstCenterOk = secondCenter.IsTranslationOf(firstCenter, candidateTranslationArray);
            //    }



            //if (cylinderOfFirst.firstBaseCurve.IsCircle())
            //{
            //    double[] firstCircleParam = cylinderOfFirst.firstBaseCurve.CircleParams;
            //    var firstCenter = new MyVertex(firstCircleParam[0], firstCircleParam[1], firstCircleParam[2]);
            //    if (possibleCylinder.firstBaseCurve.IsCircle())
            //    {
            //        double[] secondCircleParam = possibleCylinder.firstBaseCurve.CircleParams;
            //        var secondCenter = new MyVertex(secondCircleParam[0], secondCircleParam[1], secondCircleParam[2]);
            //        bool firstCenterOk = secondCenter.IsTranslationOf(firstCenter, candidateTranslationArray);
            //    }
            //    else
            //    {
            //        if (possibleCylinder.secondBaseCurve.IsCircle())
            //        {
            //            double[] secondCircleParam = possibleCylinder.secondBaseCurve.CircleParams;
            //            var secondCenter = new MyVertex(secondCircleParam[0], secondCircleParam[1],
            //                secondCircleParam[2]);
            //            bool firstCenterOk = secondCenter.IsTranslationOf(firstCenter, candidateTranslationArray);
            //        }
            //    }
            //}
            //else //obviously cylinderOfFirst is an ellipse
            //{
            //    double[] firstEllipseParam = cylinderOfFirst.firstBaseCurve.GetEllipseParams();
            //    var firstCenter = new MyVertex(firstEllipseParam[0], firstEllipseParam[1], firstEllipseParam[2]);
            //    var firstMajorRad = firstEllipseParam[3];
            //    double[] firstMajorRadAxis = { firstEllipseParam[4], firstEllipseParam[5], firstEllipseParam[6] };
            //    var firstMinorRad = firstEllipseParam[7];
            //    double[] firstMinorRadAxis = { firstEllipseParam[8], firstEllipseParam[9], firstEllipseParam[10] };
            //    if (possibleCylinder.firstBaseCurve.IsEllipse())
            //    {

            //    }
            //}
            #endregion
        }
Exemple #9
0
        public static bool CylinderOfFirstAtPosition_i_IsOkTranslation(MyRepeatedEntity firstMyRepeatedEntity,
                                                                       MyRepeatedEntity secondMyRepeatedEntity, double[] candidateTranslationArray, MyCylinder cylinderOfFirst,
                                                                       double tolerance, ref int i)
        {
            const string nameFile = "GetTranslationalPatterns.txt";

            //I compute the distance vector v between the centroidOfFirst and the Origin of the cylinderOfFirst (which pass through the axis)
            //The axis of the second MyRepeatedEntity should have the same axis direction and
            //should pass through the point = centroidOfSecond + v
            double[] originOfFirst   = cylinderOfFirst.originCylinder;
            double[] centroidOfFirst =
            {
                firstMyRepeatedEntity.centroid.x, firstMyRepeatedEntity.centroid.y,
                firstMyRepeatedEntity.centroid.z
            };

            // if centroid and origin of the cylinder are coinciding, I find another point on the cylinder axis to substitute the origin:
            if (FunctionsLC.MyEqualsArray(originOfFirst, centroidOfFirst))
            {
                originOfFirst[0] = originOfFirst[0] + cylinderOfFirst.axisDirectionCylinder[0];
                originOfFirst[1] = originOfFirst[1] + cylinderOfFirst.axisDirectionCylinder[1];
                originOfFirst[2] = originOfFirst[2] + cylinderOfFirst.axisDirectionCylinder[2];
            }

            double[] vectorToFindPointOnAxis =
            {
                originOfFirst[0] - centroidOfFirst[0],
                originOfFirst[1] - centroidOfFirst[1],
                originOfFirst[2] - centroidOfFirst[2]
            };

            double[] centroidOfSecond =
            {
                secondMyRepeatedEntity.centroid.x, secondMyRepeatedEntity.centroid.y,
                secondMyRepeatedEntity.centroid.z
            };

            double[] pointOnAxis =
            {
                centroidOfSecond[0] + vectorToFindPointOnAxis[0],
                centroidOfSecond[1] + vectorToFindPointOnAxis[1],
                centroidOfSecond[2] + vectorToFindPointOnAxis[2]
            };

            var axisToFind = FunctionsLC.ConvertPointPlusDirectionInMyLine(pointOnAxis,
                                                                           cylinderOfFirst.axisDirectionCylinder);

            var listOfPossibleCylinders =
                secondMyRepeatedEntity.listOfCylindricalSurfaces.FindAll(
                    cyl => cyl.axisCylinder.Equals(axisToFind));

            if (listOfPossibleCylinders.Any())
            {
                var numOfPossibleCylinders = listOfPossibleCylinders.Count;

                //If I find cylinders with right axis line, I check the radius correspondence,
                //the center of bases correspondence.
                //For elliptical bases I make a further control on radius axis.
                var notFound = true;
                int j        = 0;
                while (notFound && j < numOfPossibleCylinders)
                {
                    var possibleCylinder = listOfPossibleCylinders[j];
                    if (Math.Abs(cylinderOfFirst.radiusCylinder - possibleCylinder.radiusCylinder) < tolerance)
                    {
                        if (CheckOfClosedEdgesCorrespondenceTransl(cylinderOfFirst, possibleCylinder,
                                                                   candidateTranslationArray))
                        {
                            notFound = false;
                        }
                    }
                    j++;
                }
                if (notFound)
                {
                    return(false);
                }

                //if the previous cylinder is ok, i pass to the next cylinder:
                i++;
            }
            else
            {
                return(false);
            }
            return(true);
        }