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.
19 #include <Extrema_ExtElC.hxx>
20 #include <Extrema_POnCurv.hxx>
21 #include <GC_MakeArcOfCircle.hxx>
22 #include <gce_MakeCirc.hxx>
23 #include <gce_MakeLin.hxx>
24 #include <Geom_Circle.hxx>
25 #include <Geom_TrimmedCurve.hxx>
26 #include <gp_Circ.hxx>
29 #include <StdFail_NotDone.hxx>
31 //=======================================================================
32 //function : GC_MakeArcOfCircle
34 //=======================================================================
35 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Pnt& P1 ,
39 Standard_Boolean sense;
41 gce_MakeCirc Cir(P1, P2, P3);
42 TheError = Cir.Status();
43 if (TheError == gce_Done) {
44 Standard_Real Alpha1, Alpha3;//,Alpha2
45 gp_Circ C(Cir.Value());
46 //modified by NIZNHY-PKV Thu Mar 3 10:53:02 2005f
47 //Alpha1 is always =0.
48 //Alpha1 = ElCLib::Parameter(C,P1);
49 //Alpha2 = ElCLib::Parameter(C,P2);
50 //Alpha3 = ElCLib::Parameter(C,P3);
52 //if (Alpha2 >= Alpha1 && Alpha2 <= Alpha3) sense = Standard_True;
53 //else if (Alpha1 <= Alpha3 && Alpha2 >= Alpha3 ) sense = Standard_True;
54 //else sense = Standard_False;
57 Alpha3 = ElCLib::Parameter(C, P3);
59 //modified by NIZNHY-PKV Thu Mar 3 10:53:04 2005t
61 Handle(Geom_Circle) Circ = new Geom_Circle(C);
62 TheArc= new Geom_TrimmedCurve(Circ, Alpha1, Alpha3, sense);
66 //=======================================================================
67 //function : GC_MakeArcOfCircle
69 //=======================================================================
70 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Pnt& P1 ,
75 gce_MakeLin Corde(P1,P2);
76 TheError = Corde.Status();
77 if (TheError == gce_Done) {
78 gp_Lin corde(Corde.Value());
79 gp_Dir dir(corde.Direction());
81 gp_Dir Daxe(dbid^dir);
82 gp_Dir Dir1(Daxe^dir);
83 gp_Lin bis(gp_Pnt((P1.X()+P2.X())/2.,(P1.Y()+P2.Y())/2.,
84 (P1.Z()+P2.Z())/2.),Dir1);
87 Standard_Real Tol = 0.000000001;
88 Extrema_ExtElC distmin(bis,norm,Tol);
89 if (!distmin.IsDone()) { TheError = gce_IntersectionError; }
91 Standard_Integer nbext = distmin.NbExt();
92 if (nbext == 0) { TheError = gce_IntersectionError; }
94 Standard_Real TheDist = RealLast();
95 gp_Pnt pInt,pon1,pon2;
96 Standard_Integer i = 1;
97 Extrema_POnCurv Pon1,Pon2;
99 if (distmin.SquareDistance(i)<TheDist) {
100 TheDist = distmin.SquareDistance(i);
101 distmin.Points(i,Pon1,Pon2);
104 pInt = gp_Pnt((pon1.XYZ()+pon2.XYZ())/2.);
108 Standard_Real Rad = (pInt.Distance(P1)+pInt.Distance(P2))/2.;
109 cir = gp_Circ(gp_Ax2(pInt,Daxe,d),Rad);
110 Standard_Real Alpha1 = ElCLib::Parameter(cir,P1);
111 Standard_Real Alpha3 = ElCLib::Parameter(cir,P2);
112 Handle(Geom_Circle) Circ = new Geom_Circle(cir);
113 TheArc= new Geom_TrimmedCurve(Circ,Alpha1,Alpha3, Standard_True);
118 //=======================================================================
119 //function : GC_MakeArcOfCircle
121 //=======================================================================
122 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ ,
125 const Standard_Boolean Sense )
127 Standard_Real Alpha1 = ElCLib::Parameter(Circ,P1);
128 Standard_Real Alpha2 = ElCLib::Parameter(Circ,P2);
129 Handle(Geom_Circle) C = new Geom_Circle(Circ);
130 TheArc= new Geom_TrimmedCurve(C,Alpha1,Alpha2,Sense);
133 //=======================================================================
134 //function : GC_MakeArcOfCircle
136 //=======================================================================
137 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ ,
139 const Standard_Real Alpha ,
140 const Standard_Boolean Sense )
142 Standard_Real Alphafirst = ElCLib::Parameter(Circ,P);
143 Handle(Geom_Circle) C = new Geom_Circle(Circ);
144 TheArc= new Geom_TrimmedCurve(C,Alphafirst,Alpha,Sense);
147 //=======================================================================
148 //function : GC_MakeArcOfCircle
150 //=======================================================================
151 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ ,
152 const Standard_Real Alpha1 ,
153 const Standard_Real Alpha2 ,
154 const Standard_Boolean Sense )
156 Handle(Geom_Circle) C = new Geom_Circle(Circ);
157 TheArc= new Geom_TrimmedCurve(C,Alpha1,Alpha2,Sense);
160 //=======================================================================
163 //=======================================================================
164 const Handle(Geom_TrimmedCurve)& GC_MakeArcOfCircle::Value() const
166 StdFail_NotDone_Raise_if (TheError != gce_Done,
167 "GC_MakeArcOfCircle::Value() - no result");