Integration of OCCT 6.5.0 from SVN
[occt.git] / src / GC / GC_MakeArcOfCircle.cxx
1 // File:        GC_MakeArcOfCircle.cxx
2 // Created:     Fri Oct  2 16:30:57 1992
3 // Author:      Remi GILET
4 //              <reg@topsn3>
5
6 #include <GC_MakeArcOfCircle.ixx>
7 #include <gce_MakeCirc.hxx>
8 #include <gce_MakeLin.hxx>
9 #include <Geom_Circle.hxx>
10 #include <Extrema_ExtElC.hxx>
11 #include <Extrema_POnCurv.hxx>
12 #include <StdFail_NotDone.hxx>
13 #include <ElCLib.hxx>
14
15 //=======================================================================
16 //function : GC_MakeArcOfCircle
17 //purpose  : 
18 //=======================================================================
19 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Pnt&  P1 ,
20                                        const gp_Pnt&  P2 ,
21                                        const gp_Pnt&  P3  ) 
22 {
23   Standard_Boolean sense;
24   //
25   gce_MakeCirc Cir(P1, P2, P3);
26   TheError = Cir.Status();
27   if (TheError == gce_Done) {
28     Standard_Real Alpha1, Alpha3;//,Alpha2
29     gp_Circ C(Cir.Value());
30     //modified by NIZNHY-PKV Thu Mar  3 10:53:02 2005f
31     //Alpha1 is always =0.
32     //Alpha1 = ElCLib::Parameter(C,P1);
33     //Alpha2 = ElCLib::Parameter(C,P2);
34     //Alpha3 = ElCLib::Parameter(C,P3);
35     //
36     //if (Alpha2 >= Alpha1 && Alpha2 <= Alpha3) sense = Standard_True;
37     //else if (Alpha1 <= Alpha3 && Alpha2 >= Alpha3 ) sense = Standard_True;
38     //else sense = Standard_False;
39     // 
40     Alpha1=0.;
41     Alpha3 = ElCLib::Parameter(C, P3);
42     sense=Standard_True;
43     //modified by NIZNHY-PKV Thu Mar  3 10:53:04 2005t
44     
45     Handle(Geom_Circle) Circ = new Geom_Circle(C);
46     TheArc= new Geom_TrimmedCurve(Circ, Alpha1, Alpha3, sense);
47   }
48 }
49
50 //=======================================================================
51 //function : GC_MakeArcOfCircle
52 //purpose  : 
53 //=======================================================================
54 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Pnt& P1 ,
55                                        const gp_Vec& V  ,
56                                        const gp_Pnt& P2 )
57 {
58   gp_Circ cir;
59   gce_MakeLin Corde(P1,P2);
60   TheError = Corde.Status();
61   if (TheError == gce_Done) {
62     gp_Lin corde(Corde.Value());
63     gp_Dir dir(corde.Direction());
64     gp_Dir dbid(V);
65     gp_Dir Daxe(dbid^dir);
66     gp_Dir Dir1(Daxe^dir);
67     gp_Lin bis(gp_Pnt((P1.X()+P2.X())/2.,(P1.Y()+P2.Y())/2.,
68                       (P1.Z()+P2.Z())/2.),Dir1);
69     gp_Dir d(dbid^Daxe);
70     gp_Lin norm(P1,d);
71     Standard_Real Tol = 0.000000001;
72     Extrema_ExtElC distmin(bis,norm,Tol);
73     if (!distmin.IsDone()) { TheError = gce_IntersectionError; }
74     else {
75       Standard_Integer nbext = distmin.NbExt();
76       if (nbext == 0) { TheError = gce_IntersectionError; }
77       else {
78         Standard_Real TheDist = RealLast();
79         gp_Pnt pInt,pon1,pon2;
80         Standard_Integer i = 1;
81         Extrema_POnCurv Pon1,Pon2;
82         while (i<=nbext) {
83           if (distmin.SquareDistance(i)<TheDist) {
84             TheDist = distmin.SquareDistance(i);
85             distmin.Points(i,Pon1,Pon2);
86             pon1 = Pon1.Value();
87             pon2 = Pon2.Value();
88             pInt = gp_Pnt((pon1.XYZ()+pon2.XYZ())/2.);
89           }
90           i++;
91         }
92         Standard_Real Rad = (pInt.Distance(P1)+pInt.Distance(P2))/2.;
93         cir = gp_Circ(gp_Ax2(pInt,Daxe,d),Rad);
94         Standard_Real Alpha1 = ElCLib::Parameter(cir,P1);
95         Standard_Real Alpha3 = ElCLib::Parameter(cir,P2);
96         Handle(Geom_Circle) Circ = new Geom_Circle(cir);
97         TheArc= new Geom_TrimmedCurve(Circ,Alpha1,Alpha3, Standard_True);
98       }
99     }
100   }
101 }
102 //=======================================================================
103 //function : GC_MakeArcOfCircle
104 //purpose  : 
105 //=======================================================================
106 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ   ,
107                                        const gp_Pnt&  P1     ,
108                                        const gp_Pnt&  P2     ,
109                                        const Standard_Boolean  Sense  ) 
110 {
111   Standard_Real Alpha1 = ElCLib::Parameter(Circ,P1);
112   Standard_Real Alpha2 = ElCLib::Parameter(Circ,P2);
113   Handle(Geom_Circle) C = new Geom_Circle(Circ);
114   TheArc= new Geom_TrimmedCurve(C,Alpha1,Alpha2,Sense);
115   TheError = gce_Done;
116 }
117 //=======================================================================
118 //function : GC_MakeArcOfCircle
119 //purpose  : 
120 //=======================================================================
121 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ   ,
122                                        const gp_Pnt&  P      ,
123                                        const Standard_Real     Alpha  ,
124                                        const Standard_Boolean  Sense  ) 
125 {
126   Standard_Real Alphafirst = ElCLib::Parameter(Circ,P);
127   Handle(Geom_Circle) C = new Geom_Circle(Circ);
128   TheArc= new Geom_TrimmedCurve(C,Alphafirst,Alpha,Sense);
129   TheError = gce_Done;
130 }
131 //=======================================================================
132 //function : GC_MakeArcOfCircle
133 //purpose  : 
134 //=======================================================================
135 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ   ,
136                                          const Standard_Real     Alpha1 ,
137                                          const Standard_Real     Alpha2 ,
138                                          const Standard_Boolean  Sense  ) 
139 {
140   Handle(Geom_Circle) C = new Geom_Circle(Circ);
141   TheArc= new Geom_TrimmedCurve(C,Alpha1,Alpha2,Sense);
142   TheError = gce_Done;
143 }
144 //=======================================================================
145 //function : Value
146 //purpose  : 
147 //=======================================================================
148 const Handle(Geom_TrimmedCurve)& GC_MakeArcOfCircle::Value() const
149
150   StdFail_NotDone_Raise_if(!TheError == gce_Done,"");
151   return TheArc;
152 }
153 //=======================================================================
154 //function : Operator
155 //purpose  : 
156 //=======================================================================
157 const Handle(Geom_TrimmedCurve)& GC_MakeArcOfCircle::Operator() const 
158 {
159   return Value();
160 }
161 //=======================================================================
162 //function : operator
163 //purpose  : 
164 //=======================================================================
165 GC_MakeArcOfCircle::operator Handle(Geom_TrimmedCurve) () const
166 {
167   return Value();
168 }
169