b311480e |
1 | // Created on: 1992-09-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 | |
17 | #include <gce_MakeCone.ixx> |
18 | #include <StdFail_NotDone.hxx> |
19 | #include <gp.hxx> |
20 | |
21 | //========================================================================= |
22 | // Construction d un cone par son axe , le rayon de sa base et le demi + |
23 | // angle d ouverture. + |
24 | //========================================================================= |
25 | |
26 | gce_MakeCone::gce_MakeCone(const gp_Ax2& A2 , |
27 | const Standard_Real Ang , |
28 | const Standard_Real Radius) |
29 | { |
30 | if (Radius < 0.0) { TheError = gce_NegativeRadius; } |
31 | else { |
c6541a0c |
32 | if (Ang <= gp::Resolution() || M_PI/2-Ang <= gp::Resolution()) { |
7fd59977 |
33 | TheError = gce_BadAngle; |
34 | } |
35 | else { |
36 | TheError = gce_Done; |
37 | TheCone = gp_Cone(A2,Ang,Radius); |
38 | } |
39 | } |
40 | } |
41 | |
42 | //========================================================================= |
43 | // Constructions d un cone de gp par quatre points P1, P2, P3 et P4. + |
44 | // P1 et P2 donnent l axe du cone, la distance de P3 a l axe donne + |
45 | // le rayon de la base du cone et la distance de P4 a l axe donne le + |
46 | // rayon du cone pour la section passant par P4. + |
47 | //========================================================================= |
48 | |
49 | gce_MakeCone::gce_MakeCone(const gp_Pnt& P1 , |
50 | const gp_Pnt& P2 , |
51 | const gp_Pnt& P3 , |
52 | const gp_Pnt& P4 ) |
53 | { |
54 | if (P1.Distance(P2)<RealEpsilon() || P3.Distance(P4)<RealEpsilon()) { TheError = gce_ConfusedPoints; return; } |
55 | |
56 | gp_Dir D1(P2.XYZ()-P1.XYZ()); |
57 | Standard_Real cos = D1.Dot(gp_Dir(P4.XYZ()-P1.XYZ())); |
58 | Standard_Real dist = P1.Distance(P4); |
59 | gp_Pnt PP4(P1.XYZ()+cos*dist*D1.XYZ()); |
60 | cos = D1.Dot(gp_Dir(P3.XYZ()-P1.XYZ())); |
61 | dist = P1.Distance(P3); |
62 | gp_Pnt PP3(P1.XYZ()+cos*dist*D1.XYZ()); |
63 | |
64 | Standard_Real Dist13 = PP3.Distance(P1); |
65 | Standard_Real Dist14 = PP4.Distance(P1); |
66 | if(Abs(Dist13-Dist14)<RealEpsilon()) { TheError = gce_NullAngle; return; } |
67 | gp_Lin L1(P1,D1); |
68 | Standard_Real Dist3 = L1.Distance(P3); |
69 | Standard_Real Dist4 = L1.Distance(P4); |
70 | Standard_Real DifRad = Dist3-Dist4; |
71 | Standard_Real angle = Abs(ATan(DifRad/(Dist13-Dist14))); |
c6541a0c |
72 | if(Abs(M_PI/2.-angle) < RealEpsilon() || Abs(angle) < RealEpsilon()) { TheError = gce_NullRadius; return; } |
7fd59977 |
73 | Standard_Real R1 = PP3.Distance(P3); |
74 | Standard_Real R2 = PP4.Distance(P4); |
75 | if (R1 < 0.0 || R2 < 0.0) { TheError = gce_NegativeRadius; return; } |
76 | gp_Dir DD1(PP4.XYZ()-PP3.XYZ()); |
77 | gp_Dir D2; |
78 | Standard_Real x = DD1.X(); |
79 | Standard_Real y = DD1.Y(); |
80 | Standard_Real z = DD1.Z(); |
81 | if (Abs(x) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); } |
82 | else if (Abs(y) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); } |
83 | else if (Abs(z) > gp::Resolution()) { D2 = gp_Dir(0.0,-z,y); } |
84 | if (R1 > R2) { angle *= -1; } |
85 | TheCone = gp_Cone(gp_Ax2(PP3,DD1,D2),angle,R1); |
86 | TheError = gce_Done; |
87 | } |
88 | |
89 | |
90 | |
91 | //========================================================================= |
92 | // Constructions d un cone de gp par son axe et deux points P1, P2. + |
93 | // La distance de P1 a l axe donne le rayon de la base du cone et la + |
94 | // distance de P2 a l axe donne le rayon du cone pour la section passant + |
95 | // par P2. + |
96 | //========================================================================= |
97 | |
98 | gce_MakeCone::gce_MakeCone(const gp_Ax1& Axis , |
99 | const gp_Pnt& P1 , |
100 | const gp_Pnt& P2 ) |
101 | { |
102 | gp_Pnt P3(Axis.Location()); |
103 | gp_Pnt P4(P3.XYZ()+Axis.Direction().XYZ()); |
104 | gce_MakeCone Cone(P3,P4,P1,P2); |
105 | if (Cone.IsDone()) { |
106 | TheCone = Cone.Value(); |
107 | TheError = gce_Done; |
108 | } |
109 | else { |
110 | TheError = Cone.Status(); |
111 | } |
112 | } |
113 | |
114 | //========================================================================= |
115 | // Constructions d un cone parallele a un autre cone passant par un + |
116 | // donne. + |
117 | //========================================================================= |
118 | |
119 | //gce_MakeCone::gce_MakeCone(const gp_Cone& cone , |
120 | // const gp_Pnt& P ) |
121 | gce_MakeCone::gce_MakeCone(const gp_Cone& , |
122 | const gp_Pnt& ) |
123 | { |
124 | TheError = gce_ConfusedPoints; |
125 | } |
126 | |
127 | //========================================================================= |
128 | // Constructions d un cone parallele a un autre cone a une distance + |
129 | // donnee. + |
130 | //========================================================================= |
131 | |
132 | //gce_MakeCone::gce_MakeCone(const gp_Cone& cone , |
133 | // const Standard_Real Dist ) |
134 | gce_MakeCone::gce_MakeCone(const gp_Cone& , |
135 | const Standard_Real ) |
136 | { |
137 | TheError = gce_Done; |
138 | } |
139 | |
140 | //========================================================================= |
141 | // Constructions d un cone de gp par son axe et deux points P1, P2. + |
142 | // La distance de P1 a l axe donne le rayon de la base du cone et la + |
143 | // distance de P2 a l axe donne le rayon du cone pour la section passant + |
144 | // par P2. + |
145 | //========================================================================= |
146 | |
147 | gce_MakeCone::gce_MakeCone(const gp_Lin& Axis , |
148 | const gp_Pnt& P1 , |
149 | const gp_Pnt& P2 ) |
150 | { |
151 | gp_Pnt P3(Axis.Location()); |
152 | gp_Pnt P4(P3.XYZ()+Axis.Direction().XYZ()); |
153 | gce_MakeCone Cone(P3,P4,P1,P2); |
154 | if (Cone.IsDone()) { |
155 | TheCone = Cone.Value(); |
156 | TheError = gce_Done; |
157 | } |
158 | else { TheError = Cone.Status(); } |
159 | } |
160 | |
161 | //========================================================================= |
162 | // cone par deux points (axe du cone.) et deux rayons (rayon des + |
163 | // sections passant par chacun de ces points). + |
164 | //========================================================================= |
165 | |
166 | gce_MakeCone::gce_MakeCone(const gp_Pnt& P1 , |
167 | const gp_Pnt& P2 , |
168 | const Standard_Real R1 , |
169 | const Standard_Real R2 ) |
170 | { |
171 | Standard_Real dist = P1.Distance(P2); |
172 | if (dist < RealEpsilon()) { TheError = gce_NullAxis; } |
173 | else { |
174 | if (R1 < 0.0 || R2 < 0.0) { |
175 | TheError = gce_NegativeRadius; |
176 | } |
177 | else { |
178 | Standard_Real Angle = Abs(atan((R1-R2)/dist)); |
c6541a0c |
179 | if (Abs(M_PI/2.-Angle)<RealEpsilon() || Abs(Angle)<RealEpsilon()) { |
7fd59977 |
180 | TheError = gce_NullAngle; |
181 | } |
182 | else { |
183 | gp_Dir D1(P2.XYZ()-P1.XYZ()); |
184 | gp_Dir D2; |
185 | Standard_Real x = D1.X(); |
186 | Standard_Real y = D1.Y(); |
187 | Standard_Real z = D1.Z(); |
188 | if (Abs(x) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); } |
189 | else if (Abs(y) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); } |
190 | else if (Abs(z) > gp::Resolution()) { D2 = gp_Dir(0.0,-z,y); } |
191 | if (R1 > R2) { Angle *= -1; } |
192 | TheCone = gp_Cone(gp_Ax2(P1,D1,D2),Angle,R1); |
193 | TheError = gce_Done; |
194 | } |
195 | } |
196 | } |
197 | } |
198 | |
199 | const gp_Cone& gce_MakeCone::Value() const |
200 | { |
201 | StdFail_NotDone_Raise_if(!TheError == gce_Done,""); |
202 | return TheCone; |
203 | } |
204 | |
205 | const gp_Cone& gce_MakeCone::Operator() const |
206 | { |
207 | return Value(); |
208 | } |
209 | |
210 | gce_MakeCone::operator gp_Cone() const |
211 | { |
212 | return Value(); |
213 | } |
214 | |