b311480e |
1 | // Created on: 1992-10-02 |
2 | // Created by: Remi GILET |
3 | // Copyright (c) 1992-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
18 | #include <ElCLib.hxx> |
19 | #include <Extrema_ExtElC.hxx> |
20 | #include <Extrema_POnCurv.hxx> |
21 | #include <GC_MakeArcOfCircle.hxx> |
7fd59977 |
22 | #include <gce_MakeCirc.hxx> |
23 | #include <gce_MakeLin.hxx> |
24 | #include <Geom_Circle.hxx> |
42cf5bc1 |
25 | #include <Geom_TrimmedCurve.hxx> |
26 | #include <gp_Circ.hxx> |
27 | #include <gp_Pnt.hxx> |
28 | #include <gp_Vec.hxx> |
7fd59977 |
29 | #include <StdFail_NotDone.hxx> |
7fd59977 |
30 | |
31 | //======================================================================= |
32 | //function : GC_MakeArcOfCircle |
33 | //purpose : |
34 | //======================================================================= |
35 | GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Pnt& P1 , |
36 | const gp_Pnt& P2 , |
37 | const gp_Pnt& P3 ) |
38 | { |
39 | Standard_Boolean sense; |
40 | // |
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); |
51 | // |
52 | //if (Alpha2 >= Alpha1 && Alpha2 <= Alpha3) sense = Standard_True; |
53 | //else if (Alpha1 <= Alpha3 && Alpha2 >= Alpha3 ) sense = Standard_True; |
54 | //else sense = Standard_False; |
55 | // |
56 | Alpha1=0.; |
57 | Alpha3 = ElCLib::Parameter(C, P3); |
58 | sense=Standard_True; |
59 | //modified by NIZNHY-PKV Thu Mar 3 10:53:04 2005t |
60 | |
61 | Handle(Geom_Circle) Circ = new Geom_Circle(C); |
62 | TheArc= new Geom_TrimmedCurve(Circ, Alpha1, Alpha3, sense); |
63 | } |
64 | } |
65 | |
66 | //======================================================================= |
67 | //function : GC_MakeArcOfCircle |
68 | //purpose : |
69 | //======================================================================= |
70 | GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Pnt& P1 , |
71 | const gp_Vec& V , |
72 | const gp_Pnt& P2 ) |
73 | { |
74 | gp_Circ cir; |
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()); |
80 | gp_Dir dbid(V); |
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); |
85 | gp_Dir d(dbid^Daxe); |
86 | gp_Lin norm(P1,d); |
87 | Standard_Real Tol = 0.000000001; |
88 | Extrema_ExtElC distmin(bis,norm,Tol); |
89 | if (!distmin.IsDone()) { TheError = gce_IntersectionError; } |
90 | else { |
91 | Standard_Integer nbext = distmin.NbExt(); |
92 | if (nbext == 0) { TheError = gce_IntersectionError; } |
93 | else { |
94 | Standard_Real TheDist = RealLast(); |
95 | gp_Pnt pInt,pon1,pon2; |
96 | Standard_Integer i = 1; |
97 | Extrema_POnCurv Pon1,Pon2; |
98 | while (i<=nbext) { |
99 | if (distmin.SquareDistance(i)<TheDist) { |
100 | TheDist = distmin.SquareDistance(i); |
101 | distmin.Points(i,Pon1,Pon2); |
102 | pon1 = Pon1.Value(); |
103 | pon2 = Pon2.Value(); |
104 | pInt = gp_Pnt((pon1.XYZ()+pon2.XYZ())/2.); |
105 | } |
106 | i++; |
107 | } |
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); |
114 | } |
115 | } |
116 | } |
117 | } |
118 | //======================================================================= |
119 | //function : GC_MakeArcOfCircle |
120 | //purpose : |
121 | //======================================================================= |
122 | GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ , |
123 | const gp_Pnt& P1 , |
124 | const gp_Pnt& P2 , |
125 | const Standard_Boolean Sense ) |
126 | { |
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); |
131 | TheError = gce_Done; |
132 | } |
133 | //======================================================================= |
134 | //function : GC_MakeArcOfCircle |
135 | //purpose : |
136 | //======================================================================= |
137 | GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ , |
138 | const gp_Pnt& P , |
139 | const Standard_Real Alpha , |
140 | const Standard_Boolean Sense ) |
141 | { |
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); |
145 | TheError = gce_Done; |
146 | } |
147 | //======================================================================= |
148 | //function : GC_MakeArcOfCircle |
149 | //purpose : |
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 ) |
155 | { |
156 | Handle(Geom_Circle) C = new Geom_Circle(Circ); |
157 | TheArc= new Geom_TrimmedCurve(C,Alpha1,Alpha2,Sense); |
158 | TheError = gce_Done; |
159 | } |
160 | //======================================================================= |
161 | //function : Value |
162 | //purpose : |
163 | //======================================================================= |
164 | const Handle(Geom_TrimmedCurve)& GC_MakeArcOfCircle::Value() const |
165 | { |
2d2b3d53 |
166 | StdFail_NotDone_Raise_if (TheError != gce_Done, |
167 | "GC_MakeArcOfCircle::Value() - no result"); |
7fd59977 |
168 | return TheArc; |
169 | } |