// Created on: 1991-10-07 // Created by: Remi GILET // Copyright (c) 1991-1999 Matra Datavision // Copyright (c) 1999-2014 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and / or modify it // under the terms of the GNU Lesser General Public version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. //========================================================================= // CREATION of the BISSECTICE between two CIRCLES. + //========================================================================= #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //========================================================================= GccAna_Circ2dBisec:: GccAna_Circ2dBisec (const gp_Circ2d& Circ1 , const gp_Circ2d& Circ2 ) { //========================================================================= // Initialization of fields : + // - circle1 (Circle : first argument.) + // - circle2 (Line : second argument.) + // - intersection (Integer showing the smallest position + // of two circles correspondingly to each other.) + // - sameradius (Booleen showing if the two circles have + // the same radius or not.) + // - NbrSol (Integer showing the number of solutions.) + // - WellDone (Boolean showing succes or failure of the algo.). + //========================================================================= WellDone = Standard_False; Standard_Real Tol=Precision::Confusion(); Standard_Real R1 = Circ1.Radius(); Standard_Real R2 = Circ2.Radius(); if (Abs(R1-R2) <= Tol) { sameradius = Standard_True; } else { sameradius = Standard_False; } if (R1 < R2) { circle1 = gp_Circ2d(Circ2); circle2 = gp_Circ2d(Circ1); R1 = circle1.Radius(); R2 = circle2.Radius(); } else { circle1 = gp_Circ2d(Circ1); circle2 = gp_Circ2d(Circ2); } Standard_Real dist = circle2.Location().Distance(circle1.Location()); if (R1-dist-R2 > Tol) { intersection = 0; NbrSol = 2; WellDone = Standard_True; } else if (Abs(R1-dist-R2) <= Tol) { intersection = 1; if (sameradius) { NbrSol = 0; WellDone = Standard_True; } else { NbrSol = 2; WellDone = Standard_True; } } else if ((dist+R2-R1 > Tol) && (R1-dist+R2 > Tol)) { intersection = 2; if (sameradius) { NbrSol = 2; WellDone = Standard_True; } else { NbrSol = 3; WellDone = Standard_True; } } else if (Abs(R1-dist+R2) <= Tol) { intersection = 3; if (sameradius) { NbrSol = 2; WellDone = Standard_True; } else { NbrSol = 3; WellDone = Standard_True; } } else { intersection = 4; if (sameradius) { NbrSol = 3; WellDone = Standard_True; } else { NbrSol = 4; WellDone = Standard_True; } } } //========================================================================= // Processing. + // Return the coordinates of centers of circles circle1 and circle2 + // (xcencir1, ycencir1, xcencir2, ycencir2). + // Also return the radiuses of two circles R1 and R2. + //========================================================================= Handle(GccInt_Bisec) GccAna_Circ2dBisec:: ThisSolution (const Standard_Integer Index) const { Standard_Real Tol = 1.e-14; Handle(GccInt_Bisec) bissol; if (!WellDone) { StdFail_NotDone::Raise(); } else if (Index <= 0 || Index > NbrSol) { Standard_OutOfRange::Raise(); } else { Standard_Real xcencir1 = circle1.Location().X(); Standard_Real ycencir1 = circle1.Location().Y(); Standard_Real xcencir2 = circle2.Location().X(); Standard_Real ycencir2 = circle2.Location().Y(); Standard_Real dist = circle1.Location().Distance(circle2.Location()); gp_Pnt2d pcen((xcencir1+xcencir2)/2.0,(ycencir1+ycencir2)/2.0); gp_Dir2d dircen,medcen; if (dist > Tol) { dircen.SetCoord(xcencir2-xcencir1,ycencir2-ycencir1); medcen.SetCoord(ycencir2-ycencir1,xcencir1-xcencir2); } gp_Dir2d dirx(1.0,0.0); gp_Ax2d acenx(pcen,dirx); gp_Ax2d acencen(pcen,dircen); Standard_Real R1 = circle1.Radius(); Standard_Real R2 = circle2.Radius(); if ((NbrSol == 1) && (intersection == 0)) { Standard_Real R; if (Index == 1) R = (R1+R2)/2.0; else R = (R1-R2)/2.0; gp_Circ2d C(acenx,R); bissol = new GccInt_BCirc(C); // ============================= } else if ((NbrSol == 2) && (intersection == 1)) { if (Index == 1) { gp_Elips2d E(acencen, (R1+R2)/2.0,Sqrt((R1*R1+R2*R2-dist*dist)/4.+R1*R2/2.)); bissol = new GccInt_BElips(E); // ============================= } else if (Index == 2) { gp_Lin2d L(circle1.Location(), dircen); bissol = new GccInt_BLine(L); // ============================= } } else if ((NbrSol == 2) && (intersection == 0)) { if (Index == 1) { if (Abs(xcencir2-xcencir1)