1 // Created on: 1992-09-02
2 // Created by: Remi GILET
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
19 #include <gce_MakeCirc2d.hxx>
21 #include <gp_Ax2d.hxx>
22 #include <gp_Ax22d.hxx>
23 #include <gp_Circ2d.hxx>
24 #include <gp_Lin2d.hxx>
25 #include <gp_Pnt2d.hxx>
26 #include <IntAna2d_AnaIntersection.hxx>
27 #include <IntAna2d_IntPoint.hxx>
28 #include <StdFail_NotDone.hxx>
30 //=========================================================================
31 // Creation d un cercle 2d de gp passant par trois points. +
32 // Trois cas de figures : +
33 // 1/ Les trois points sont confondus. +
34 // ----------------------------------- +
35 // Le resultat est le cercle centre en Point1 de rayon zero. +
36 // 2/ Deux des trois points sont confondus. +
37 // ---------------------------------------- +
38 // On cree la mediatrice a deux points non confondus ainsi que la +
39 // droite passant par ces deux points. +
40 // La solution a pour centre l intersection de ces deux droite et +
41 // pour rayon la distance entre ce centre et l un des trois points. +
42 // 3/ Les trois points sont distinct. +
43 // ---------------------------------- +
44 // On cree la mediatrice a P1P2 ainsi que la mediatrice a P1P3. +
45 // La solution a pour centre l intersection de ces deux droite et +
46 // pour rayon la distance entre ce centre et l un des trois points. +
47 //=========================================================================
48 gce_MakeCirc2d::gce_MakeCirc2d(const gp_Pnt2d& P1 ,
52 gp_Dir2d dirx(1.0,0.0);
54 //=========================================================================
56 //=========================================================================
58 Standard_Real dist1 = P1.Distance(P2);
59 Standard_Real dist2 = P1.Distance(P3);
60 Standard_Real dist3 = P2.Distance(P3);
62 if ((dist1<gp::Resolution()) && (dist2<gp::Resolution()) &&
63 (dist3<gp::Resolution())) {
64 TheCirc2d = gp_Circ2d(gp_Ax2d(P1,dirx),0.0);
70 Standard_Real x1,y1,x2,y2,x3,y3;
74 if (dist1 >= RealEpsilon()) {
75 L1 = gp_Lin2d(gp_Pnt2d((P1.XY()+P2.XY())/2.0),
76 gp_Dir2d(P1.Y()-P2.Y(),P2.X()-P1.X()));
78 if (dist2 >= RealEpsilon()) {
79 L2 = gp_Lin2d(gp_Pnt2d((P1.XY()+P3.XY())/2.0),
80 gp_Dir2d(P1.Y()-P3.Y(),P3.X()-P1.X()));
82 if (dist2 <= RealEpsilon()) {
83 L2 = gp_Lin2d(P1,gp_Dir2d(P1.Y()-P2.Y(),P2.X()-P1.X()));
85 else if (dist1 <= RealEpsilon()) {
86 L1 = gp_Lin2d(P1,gp_Dir2d(P1.Y()-P3.Y(),P3.X()-P1.X()));
88 else if (dist3 <= RealEpsilon()) {
89 L2 = gp_Lin2d(P1,gp_Dir2d(P1.Y()-P2.Y(),P2.X()-P1.X()));
91 IntAna2d_AnaIntersection Intp(L1,L2);
93 if (!Intp.IsEmpty()) {
94 gp_Pnt2d pInt(Intp.Point(1).Value());
95 dist1 = P1.Distance(pInt);
96 dist2 = P2.Distance(pInt);
97 dist3 = P3.Distance(pInt);
100 gp_Dir2d d1(x1-xc,y1-yc);
101 gp_Dir2d d2(xc-x3,yc-y3);
102 TheCirc2d = gp_Circ2d(gp_Ax22d(pInt,d1,d2),(dist1+dist2+dist3)/3.);
103 Standard_Real Alpha1 = ElCLib::Parameter(TheCirc2d,P1);
104 Standard_Real Alpha2 = ElCLib::Parameter(TheCirc2d,P2);
105 Standard_Real Alpha3 = ElCLib::Parameter(TheCirc2d,P3);
106 if (!((Alpha1 <= Alpha2) && (Alpha2 <= Alpha3))) {
113 TheError = gce_IntersectionError;
118 //==========================================================================
119 // Creation d un gp_Circ2d par son Axe <XAxis> et son rayon <Radius>. +
120 //==========================================================================
122 gce_MakeCirc2d::gce_MakeCirc2d(const gp_Ax2d& XAxis ,
123 const Standard_Real Radius ,
124 const Standard_Boolean Sense )
127 TheCirc2d = gp_Circ2d(XAxis,Radius,Sense);
131 TheError = gce_NegativeRadius;
135 //==========================================================================
136 // Creation d un gp_Circ2d par son Repere <Axis> et son rayon <Radius>. +
137 //==========================================================================
139 gce_MakeCirc2d::gce_MakeCirc2d(const gp_Ax22d& Axis ,
140 const Standard_Real Radius )
143 TheCirc2d = gp_Circ2d(Axis,Radius);
147 TheError = gce_NegativeRadius;
151 //==========================================================================
152 // Creation d un gp_Circ2d par son centre <Center> et son rayon +
154 //==========================================================================
156 gce_MakeCirc2d::gce_MakeCirc2d(const gp_Pnt2d& Center ,
157 const Standard_Real Radius ,
158 const Standard_Boolean Sense )
161 TheCirc2d = gp_Circ2d(gp_Ax2d(Center,gp_Dir2d(1.0,0.0)),Radius,Sense);
165 TheError = gce_NegativeRadius;
169 //==========================================================================
170 // Creation d un gp_Circ2d par son centre <Center> et un point de sa +
171 // circonference <Point>. +
172 //==========================================================================
174 gce_MakeCirc2d::gce_MakeCirc2d(const gp_Pnt2d& Center ,
175 const gp_Pnt2d& Point ,
176 const Standard_Boolean Sense )
178 TheCirc2d = gp_Circ2d(gp_Ax2d(Center,gp_Dir2d(1.0,0.0)),
179 Point.Distance(Center),Sense);
183 //==========================================================================
184 // Creation d un cercle <TheCirc2d> concentrique a <Circ> passant par le +
186 //==========================================================================
188 gce_MakeCirc2d::gce_MakeCirc2d(const gp_Circ2d& Circ ,
189 const gp_Pnt2d& Point )
191 TheCirc2d = gp_Circ2d(Circ.Axis(),Point.Distance(Circ.Location()));
195 //==========================================================================
196 // Creation d un cercle <TheCirc2d> concentrique a <Circ> a une distance +
198 //==========================================================================
200 gce_MakeCirc2d::gce_MakeCirc2d(const gp_Circ2d& Circ ,
201 const Standard_Real Dist1 )
203 TheCirc2d = gp_Circ2d(Circ.Axis(),Abs(Circ.Radius()+Dist1));
207 const gp_Circ2d& gce_MakeCirc2d::Value() const
209 StdFail_NotDone_Raise_if(TheError != gce_Done,"");
213 const gp_Circ2d& gce_MakeCirc2d::Operator() const
218 gce_MakeCirc2d::operator gp_Circ2d() const