1 // Created on: 1992-10-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.
17 #include <GC_MakeArcOfCircle.ixx>
18 #include <gce_MakeCirc.hxx>
19 #include <gce_MakeLin.hxx>
20 #include <Geom_Circle.hxx>
21 #include <Extrema_ExtElC.hxx>
22 #include <Extrema_POnCurv.hxx>
23 #include <StdFail_NotDone.hxx>
26 //=======================================================================
27 //function : GC_MakeArcOfCircle
29 //=======================================================================
30 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Pnt& P1 ,
34 Standard_Boolean sense;
36 gce_MakeCirc Cir(P1, P2, P3);
37 TheError = Cir.Status();
38 if (TheError == gce_Done) {
39 Standard_Real Alpha1, Alpha3;//,Alpha2
40 gp_Circ C(Cir.Value());
41 //modified by NIZNHY-PKV Thu Mar 3 10:53:02 2005f
42 //Alpha1 is always =0.
43 //Alpha1 = ElCLib::Parameter(C,P1);
44 //Alpha2 = ElCLib::Parameter(C,P2);
45 //Alpha3 = ElCLib::Parameter(C,P3);
47 //if (Alpha2 >= Alpha1 && Alpha2 <= Alpha3) sense = Standard_True;
48 //else if (Alpha1 <= Alpha3 && Alpha2 >= Alpha3 ) sense = Standard_True;
49 //else sense = Standard_False;
52 Alpha3 = ElCLib::Parameter(C, P3);
54 //modified by NIZNHY-PKV Thu Mar 3 10:53:04 2005t
56 Handle(Geom_Circle) Circ = new Geom_Circle(C);
57 TheArc= new Geom_TrimmedCurve(Circ, Alpha1, Alpha3, sense);
61 //=======================================================================
62 //function : GC_MakeArcOfCircle
64 //=======================================================================
65 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Pnt& P1 ,
70 gce_MakeLin Corde(P1,P2);
71 TheError = Corde.Status();
72 if (TheError == gce_Done) {
73 gp_Lin corde(Corde.Value());
74 gp_Dir dir(corde.Direction());
76 gp_Dir Daxe(dbid^dir);
77 gp_Dir Dir1(Daxe^dir);
78 gp_Lin bis(gp_Pnt((P1.X()+P2.X())/2.,(P1.Y()+P2.Y())/2.,
79 (P1.Z()+P2.Z())/2.),Dir1);
82 Standard_Real Tol = 0.000000001;
83 Extrema_ExtElC distmin(bis,norm,Tol);
84 if (!distmin.IsDone()) { TheError = gce_IntersectionError; }
86 Standard_Integer nbext = distmin.NbExt();
87 if (nbext == 0) { TheError = gce_IntersectionError; }
89 Standard_Real TheDist = RealLast();
90 gp_Pnt pInt,pon1,pon2;
91 Standard_Integer i = 1;
92 Extrema_POnCurv Pon1,Pon2;
94 if (distmin.SquareDistance(i)<TheDist) {
95 TheDist = distmin.SquareDistance(i);
96 distmin.Points(i,Pon1,Pon2);
99 pInt = gp_Pnt((pon1.XYZ()+pon2.XYZ())/2.);
103 Standard_Real Rad = (pInt.Distance(P1)+pInt.Distance(P2))/2.;
104 cir = gp_Circ(gp_Ax2(pInt,Daxe,d),Rad);
105 Standard_Real Alpha1 = ElCLib::Parameter(cir,P1);
106 Standard_Real Alpha3 = ElCLib::Parameter(cir,P2);
107 Handle(Geom_Circle) Circ = new Geom_Circle(cir);
108 TheArc= new Geom_TrimmedCurve(Circ,Alpha1,Alpha3, Standard_True);
113 //=======================================================================
114 //function : GC_MakeArcOfCircle
116 //=======================================================================
117 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ ,
120 const Standard_Boolean Sense )
122 Standard_Real Alpha1 = ElCLib::Parameter(Circ,P1);
123 Standard_Real Alpha2 = ElCLib::Parameter(Circ,P2);
124 Handle(Geom_Circle) C = new Geom_Circle(Circ);
125 TheArc= new Geom_TrimmedCurve(C,Alpha1,Alpha2,Sense);
128 //=======================================================================
129 //function : GC_MakeArcOfCircle
131 //=======================================================================
132 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ ,
134 const Standard_Real Alpha ,
135 const Standard_Boolean Sense )
137 Standard_Real Alphafirst = ElCLib::Parameter(Circ,P);
138 Handle(Geom_Circle) C = new Geom_Circle(Circ);
139 TheArc= new Geom_TrimmedCurve(C,Alphafirst,Alpha,Sense);
142 //=======================================================================
143 //function : GC_MakeArcOfCircle
145 //=======================================================================
146 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ ,
147 const Standard_Real Alpha1 ,
148 const Standard_Real Alpha2 ,
149 const Standard_Boolean Sense )
151 Handle(Geom_Circle) C = new Geom_Circle(Circ);
152 TheArc= new Geom_TrimmedCurve(C,Alpha1,Alpha2,Sense);
155 //=======================================================================
158 //=======================================================================
159 const Handle(Geom_TrimmedCurve)& GC_MakeArcOfCircle::Value() const
161 StdFail_NotDone_Raise_if(!TheError == gce_Done,"");
164 //=======================================================================
165 //function : Operator
167 //=======================================================================
168 const Handle(Geom_TrimmedCurve)& GC_MakeArcOfCircle::Operator() const
172 //=======================================================================
173 //function : operator
175 //=======================================================================
176 GC_MakeArcOfCircle::operator Handle(Geom_TrimmedCurve) () const