1 // File: gce_MakeCirc2d.cxx
2 // Created: Wed Sep 2 10:34:28 1992
6 #include <gce_MakeCirc2d.ixx>
7 #include <StdFail_NotDone.hxx>
9 #include <gp_Lin2d.hxx>
11 #include <IntAna2d_AnaIntersection.hxx>
12 #include <IntAna2d_IntPoint.hxx>
14 //=========================================================================
15 // Creation d un cercle 2d de gp passant par trois points. +
16 // Trois cas de figures : +
17 // 1/ Les trois points sont confondus. +
18 // ----------------------------------- +
19 // Le resultat est le cercle centre en Point1 de rayon zero. +
20 // 2/ Deux des trois points sont confondus. +
21 // ---------------------------------------- +
22 // On cree la mediatrice a deux points non confondus ainsi que la +
23 // droite passant par ces deux points. +
24 // La solution a pour centre l intersection de ces deux droite et +
25 // pour rayon la distance entre ce centre et l un des trois points. +
26 // 3/ Les trois points sont distinct. +
27 // ---------------------------------- +
28 // On cree la mediatrice a P1P2 ainsi que la mediatrice a P1P3. +
29 // La solution a pour centre l intersection de ces deux droite et +
30 // pour rayon la distance entre ce centre et l un des trois points. +
31 //=========================================================================
33 gce_MakeCirc2d::gce_MakeCirc2d(const gp_Pnt2d& P1 ,
37 gp_Dir2d dirx(1.0,0.0);
39 //=========================================================================
41 //=========================================================================
43 Standard_Real dist1 = P1.Distance(P2);
44 Standard_Real dist2 = P1.Distance(P3);
45 Standard_Real dist3 = P2.Distance(P3);
47 if ((dist1<gp::Resolution()) && (dist2<gp::Resolution()) &&
48 (dist3<gp::Resolution())) {
49 TheCirc2d = gp_Circ2d(gp_Ax2d(P1,dirx),0.0);
55 Standard_Real x1,y1,x2,y2,x3,y3;
59 if (dist1 >= RealEpsilon()) {
60 L1 = gp_Lin2d(gp_Pnt2d((P1.XY()+P2.XY())/2.0),
61 gp_Dir2d(P1.Y()-P2.Y(),P2.X()-P1.X()));
63 if (dist2 >= RealEpsilon()) {
64 L2 = gp_Lin2d(gp_Pnt2d((P1.XY()+P3.XY())/2.0),
65 gp_Dir2d(P1.Y()-P3.Y(),P3.X()-P1.X()));
67 if (dist2 <= RealEpsilon()) {
68 L2 = gp_Lin2d(P1,gp_Dir2d(P1.Y()-P2.Y(),P2.X()-P1.X()));
70 else if (dist1 <= RealEpsilon()) {
71 L1 = gp_Lin2d(P1,gp_Dir2d(P1.Y()-P3.Y(),P3.X()-P1.X()));
73 else if (dist3 <= RealEpsilon()) {
74 L2 = gp_Lin2d(P1,gp_Dir2d(P1.Y()-P2.Y(),P2.X()-P1.X()));
76 IntAna2d_AnaIntersection Intp(L1,L2);
78 if (!Intp.IsEmpty()) {
79 gp_Pnt2d pInt(Intp.Point(1).Value());
80 dist1 = P1.Distance(pInt);
81 dist2 = P2.Distance(pInt);
82 dist3 = P3.Distance(pInt);
85 gp_Dir2d d1(x1-xc,y1-yc);
86 gp_Dir2d d2(xc-x3,yc-y3);
87 TheCirc2d = gp_Circ2d(gp_Ax22d(pInt,d1,d2),(dist1+dist2+dist3)/3.);
88 Standard_Real Alpha1 = ElCLib::Parameter(TheCirc2d,P1);
89 Standard_Real Alpha2 = ElCLib::Parameter(TheCirc2d,P2);
90 Standard_Real Alpha3 = ElCLib::Parameter(TheCirc2d,P3);
91 if (!((Alpha1 <= Alpha2) && (Alpha2 <= Alpha3))) {
98 TheError = gce_IntersectionError;
103 //==========================================================================
104 // Creation d un gp_Circ2d par son Axe <XAxis> et son rayon <Radius>. +
105 //==========================================================================
107 gce_MakeCirc2d::gce_MakeCirc2d(const gp_Ax2d& XAxis ,
108 const Standard_Real Radius ,
109 const Standard_Boolean Sense )
112 TheCirc2d = gp_Circ2d(XAxis,Radius,Sense);
116 TheError = gce_NegativeRadius;
120 //==========================================================================
121 // Creation d un gp_Circ2d par son Repere <Axis> et son rayon <Radius>. +
122 //==========================================================================
124 gce_MakeCirc2d::gce_MakeCirc2d(const gp_Ax22d& Axis ,
125 const Standard_Real Radius )
128 TheCirc2d = gp_Circ2d(Axis,Radius);
132 TheError = gce_NegativeRadius;
136 //==========================================================================
137 // Creation d un gp_Circ2d par son centre <Center> et son rayon +
139 //==========================================================================
141 gce_MakeCirc2d::gce_MakeCirc2d(const gp_Pnt2d& Center ,
142 const Standard_Real Radius ,
143 const Standard_Boolean Sense )
146 TheCirc2d = gp_Circ2d(gp_Ax2d(Center,gp_Dir2d(1.0,0.0)),Radius,Sense);
150 TheError = gce_NegativeRadius;
154 //==========================================================================
155 // Creation d un gp_Circ2d par son centre <Center> et un point de sa +
156 // circonference <Point>. +
157 //==========================================================================
159 gce_MakeCirc2d::gce_MakeCirc2d(const gp_Pnt2d& Center ,
160 const gp_Pnt2d& Point ,
161 const Standard_Boolean Sense )
163 TheCirc2d = gp_Circ2d(gp_Ax2d(Center,gp_Dir2d(1.0,0.0)),
164 Point.Distance(Center),Sense);
168 //==========================================================================
169 // Creation d un cercle <TheCirc2d> concentrique a <Circ> passant par le +
171 //==========================================================================
173 gce_MakeCirc2d::gce_MakeCirc2d(const gp_Circ2d& Circ ,
174 const gp_Pnt2d& Point )
176 TheCirc2d = gp_Circ2d(Circ.Axis(),Point.Distance(Circ.Location()));
180 //==========================================================================
181 // Creation d un cercle <TheCirc2d> concentrique a <Circ> a une distance +
183 //==========================================================================
185 gce_MakeCirc2d::gce_MakeCirc2d(const gp_Circ2d& Circ ,
186 const Standard_Real Dist1 )
188 TheCirc2d = gp_Circ2d(Circ.Axis(),Abs(Circ.Radius()+Dist1));
192 const gp_Circ2d& gce_MakeCirc2d::Value() const
194 StdFail_NotDone_Raise_if(!TheError == gce_Done,"");
198 const gp_Circ2d& gce_MakeCirc2d::Operator() const
203 gce_MakeCirc2d::operator gp_Circ2d() const