// Created on: 1992-09-02 // Created by: Remi GILET // Copyright (c) 1992-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. #include #include #include #include #include #include #include #include //======================================================================= //function : gce_MakeCirc //purpose : // Creation d un cercle 3d de gp passant par trois points. + // Trois cas de figures : + // 1/ Les trois points sont confondus. + // ----------------------------------- + // Le resultat est le cercle centre en Point1 de rayon zero. + // 2/ Deux des trois points sont confondus. + // ---------------------------------------- + // Pas de solution (Erreur : Points confondus). + // 3/ Les trois points sont distinct. + // ---------------------------------- + // On cree la mediatrice a P1P2 ainsi que la mediatrice a P1P3. + // La solution a pour centre l intersection de ces deux droite et + // pour rayon la distance entre ce centre et l un des trois points. + //========================================================================= gce_MakeCirc::gce_MakeCirc(const gp_Pnt& P1 , const gp_Pnt& P2 , const gp_Pnt& P3) { //========================================================================= // Traitement. + //========================================================================= Standard_Real dist1, dist2, dist3, aResolution; // aResolution=gp::Resolution(); // dist1 = P1.Distance(P2); dist2 = P1.Distance(P3); dist3 = P2.Distance(P3); // if ((dist1= aResolution && dist2 >= aResolution)) { TheError = gce_ConfusedPoints; return; } // Standard_Real x1,y1,z1,x2,y2,z2,x3,y3,z3; // P1.Coord(x1,y1,z1); P2.Coord(x2,y2,z2); P3.Coord(x3,y3,z3); gp_Dir Dir1(x2-x1,y2-y1,z2-z1); gp_Dir Dir2(x3-x2,y3-y2,z3-z2); // gp_Ax1 anAx1(P1, Dir1); gp_Lin aL12 (anAx1); if (aL12.Distance(P3), son plan et + // son rayon . + //========================================================================= gce_MakeCirc::gce_MakeCirc(const gp_Pnt& Center , const gp_Pln& Plane , const Standard_Real Radius ) { gce_MakeCirc C = gce_MakeCirc(Center,Plane.Position().Direction(),Radius); TheCirc = C.Value(); TheError = C.Status(); } //======================================================================= //function : gce_MakeCirc //purpose : Creation d un gp_Circ par son centre
, //sa normale et son rayon . //======================================================================= gce_MakeCirc::gce_MakeCirc(const gp_Pnt& Center , const gp_Dir& Norm , const Standard_Real Radius ) { if (Radius < 0.) { TheError = gce_NegativeRadius; } else { Standard_Real A = Norm.X(); Standard_Real B = Norm.Y(); Standard_Real C = Norm.Z(); Standard_Real Aabs = Abs(A); Standard_Real Babs = Abs(B); Standard_Real Cabs = Abs(C); gp_Ax2 Pos; //========================================================================= // pour determiner l'axe X : + // on dit que le produit scalaire Vx.Norm = 0. + // et on recherche le max(A,B,C) pour faire la division. + // l'une des coordonnees du vecteur est nulle. + //========================================================================= if( Babs <= Aabs && Babs <= Cabs) { if(Aabs > Cabs) { Pos = gp_Ax2(Center,Norm,gp_Dir(-C,0.,A)); } else { Pos = gp_Ax2(Center,Norm,gp_Dir(C,0.,-A)); } } else if( Aabs <= Babs && Aabs <= Cabs) { if(Babs > Cabs) { Pos = gp_Ax2(Center,Norm,gp_Dir(0.,-C,B)); } else { Pos = gp_Ax2(Center,Norm,gp_Dir(0.,C,-B)); } } else { if(Aabs > Babs) { Pos = gp_Ax2(Center,Norm,gp_Dir(-B,A,0.)); } else { Pos = gp_Ax2(Center,Norm,gp_Dir(B,-A,0.)); } } TheCirc = gp_Circ(Pos,Radius); TheError = gce_Done; } } //======================================================================= //function : gce_MakeCirc //purpose : Creation d un gp_Circ par son centre
, // sa normale et son rayon //======================================================================= gce_MakeCirc::gce_MakeCirc(const gp_Pnt& Center , const gp_Pnt& Ptaxis , const Standard_Real Radius ) { if (Radius < 0.) { TheError = gce_NegativeRadius; } else { if (Center.Distance(Ptaxis) <= gp::Resolution()) { TheError = gce_NullAxis; } else { Standard_Real A = Ptaxis.X()-Center.X(); Standard_Real B = Ptaxis.Y()-Center.Y(); Standard_Real C = Ptaxis.Z()-Center.Z(); Standard_Real Aabs = Abs(A); Standard_Real Babs = Abs(B); Standard_Real Cabs = Abs(C); gp_Ax2 Pos; //========================================================================= // pour determiner l'axe X : + // on dit que le produit scalaire Vx.Norm = 0. + // et on recherche le max(A,B,C) pour faire la division. + // l'une des coordonnees du vecteur est nulle. + //========================================================================= gp_Dir Norm = gce_MakeDir(Center,Ptaxis); if( Babs <= Aabs && Babs <= Cabs) { if(Aabs > Cabs) { Pos = gp_Ax2(Center,Norm,gp_Dir(-C,0.,A)); } else { Pos = gp_Ax2(Center,Norm,gp_Dir(C,0.,-A)); } } else if( Aabs <= Babs && Aabs <= Cabs) { if(Babs > Cabs) { Pos = gp_Ax2(Center,Norm,gp_Dir(0.,-C,B)); } else { Pos = gp_Ax2(Center,Norm,gp_Dir(0.,C,-B)); } } else { if(Aabs > Babs) { Pos = gp_Ax2(Center,Norm,gp_Dir(-B,A,0.)); } else { Pos = gp_Ax2(Center,Norm,gp_Dir(B,-A,0.)); } } TheCirc = gp_Circ(Pos,Radius); TheError = gce_Done; } } } //======================================================================= //function : gce_MakeCirc //purpose : Creation d un gp_Circ par son axe et son rayon . //======================================================================= gce_MakeCirc::gce_MakeCirc(const gp_Ax1& Axis , const Standard_Real Radius ) { if (Radius < 0.) { TheError = gce_NegativeRadius; } else { gp_Dir Norm(Axis.Direction()); gp_Pnt Center(Axis.Location()); Standard_Real A = Norm.X(); Standard_Real B = Norm.Y(); Standard_Real C = Norm.Z(); Standard_Real Aabs = Abs(A); Standard_Real Babs = Abs(B); Standard_Real Cabs = Abs(C); gp_Ax2 Pos; //========================================================================= // pour determiner l'axe X : + // on dit que le produit scalaire Vx.Norm = 0. + // et on recherche le max(A,B,C) pour faire la division. + // l'une des coordonnees du vecteur est nulle. + //========================================================================= if( Babs <= Aabs && Babs <= Cabs) { if(Aabs > Cabs) { Pos = gp_Ax2(Center,Norm,gp_Dir(-C,0.,A)); } else { Pos = gp_Ax2(Center,Norm,gp_Dir(C,0.,-A)); } } else if( Aabs <= Babs && Aabs <= Cabs) { if(Babs > Cabs) { Pos = gp_Ax2(Center,Norm,gp_Dir(0.,-C,B)); } else { Pos = gp_Ax2(Center,Norm,gp_Dir(0.,C,-B)); } } else { if(Aabs > Babs) { Pos = gp_Ax2(Center,Norm,gp_Dir(-B,A,0.)); } else { Pos = gp_Ax2(Center,Norm,gp_Dir(B,-A,0.)); } } TheCirc = gp_Circ(Pos,Radius); TheError = gce_Done; } } //======================================================================= //function : gce_MakeCirc //purpose : Creation d un gp_Circ concentrique a un autre gp_circ a une distance + // donnee. //======================================================================= gce_MakeCirc::gce_MakeCirc(const gp_Circ& Circ , const Standard_Real Dist ) { Standard_Real Rad = Circ.Radius()+Dist; if (Rad < 0.) { TheError = gce_NegativeRadius; } else { TheCirc = gp_Circ(Circ.Position(),Rad); TheError = gce_Done; } } //======================================================================= //function : gce_MakeCirc //purpose : Creation d un gp_Circ concentrique a un autre gp_circ dont le rayon // est egal a la distance de a l axe de . //======================================================================= gce_MakeCirc::gce_MakeCirc(const gp_Circ& Circ , const gp_Pnt& P ) { Standard_Real Rad = gp_Lin(Circ.Axis()).Distance(P); TheCirc = gp_Circ(Circ.Position(),Rad); TheError = gce_Done; } //======================================================================= //function : Value //purpose : //======================================================================= const gp_Circ& gce_MakeCirc::Value() const { StdFail_NotDone_Raise_if(!TheError == gce_Done,""); return TheCirc; } //======================================================================= //function : Operator //purpose : //======================================================================= const gp_Circ& gce_MakeCirc::Operator() const { return Value(); } //======================================================================= //function : operator //purpose : //======================================================================= gce_MakeCirc::operator gp_Circ() const { return Value(); }