b311480e |
1 | // Created on: 1993-03-10 |
2 | // Created by: JCV |
3 | // Copyright (c) 1993-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 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <ElSLib.hxx> |
19 | #include <Geom_Circle.hxx> |
20 | #include <Geom_ConicalSurface.hxx> |
21 | #include <Geom_Curve.hxx> |
22 | #include <Geom_Geometry.hxx> |
23 | #include <Geom_Line.hxx> |
24 | #include <GeomAbs_UVSense.hxx> |
7fd59977 |
25 | #include <gp.hxx> |
7fd59977 |
26 | #include <gp_Ax2d.hxx> |
42cf5bc1 |
27 | #include <gp_Ax3.hxx> |
28 | #include <gp_Circ.hxx> |
29 | #include <gp_Cone.hxx> |
7fd59977 |
30 | #include <gp_Dir.hxx> |
42cf5bc1 |
31 | #include <gp_GTrsf2d.hxx> |
32 | #include <gp_Lin.hxx> |
33 | #include <gp_Pnt.hxx> |
34 | #include <gp_Trsf.hxx> |
35 | #include <gp_Vec.hxx> |
36 | #include <gp_XYZ.hxx> |
37 | #include <Precision.hxx> |
38 | #include <Standard_ConstructionError.hxx> |
39 | #include <Standard_RangeError.hxx> |
40 | #include <Standard_Type.hxx> |
7fd59977 |
41 | |
92efcf78 |
42 | IMPLEMENT_STANDARD_RTTIEXT(Geom_ConicalSurface,Geom_ElementarySurface) |
43 | |
7fd59977 |
44 | typedef Geom_ConicalSurface ConicalSurface; |
7fd59977 |
45 | typedef gp_Ax1 Ax1; |
46 | typedef gp_Ax2 Ax2; |
47 | typedef gp_Ax3 Ax3; |
48 | typedef gp_Circ Circ; |
49 | typedef gp_Dir Dir; |
50 | typedef gp_Lin Lin; |
51 | typedef gp_Pnt Pnt; |
52 | typedef gp_Trsf Trsf; |
53 | typedef gp_Vec Vec; |
54 | typedef gp_XYZ XYZ; |
55 | |
7fd59977 |
56 | //======================================================================= |
57 | //function : Copy |
58 | //purpose : |
59 | //======================================================================= |
60 | |
61 | Handle(Geom_Geometry) Geom_ConicalSurface::Copy () const { |
62 | |
c04c30b3 |
63 | Handle(Geom_ConicalSurface) Cs; |
7fd59977 |
64 | Cs = new ConicalSurface (pos, semiAngle, radius); |
65 | return Cs; |
66 | } |
67 | |
68 | //======================================================================= |
69 | //function : Geom_ConicalSurface |
70 | //purpose : |
71 | //======================================================================= |
72 | |
73 | Geom_ConicalSurface::Geom_ConicalSurface ( const Ax3& A3 , |
74 | const Standard_Real Ang, |
75 | const Standard_Real R) : |
76 | radius(R), semiAngle (Ang) |
77 | { |
78 | |
c6541a0c |
79 | if (R < 0.0 || Abs(Ang) <= gp::Resolution() || Abs(Ang) >= M_PI/2.0 - gp::Resolution()) |
9775fa61 |
80 | throw Standard_ConstructionError(); |
7fd59977 |
81 | |
82 | pos = A3; |
83 | } |
84 | |
85 | |
86 | //======================================================================= |
87 | //function : Geom_ConicalSurface |
88 | //purpose : |
89 | //======================================================================= |
90 | |
91 | Geom_ConicalSurface::Geom_ConicalSurface ( const gp_Cone& C ) |
92 | : radius (C.RefRadius()), semiAngle (C.SemiAngle()) |
93 | { |
94 | pos = C.Position(); |
95 | } |
96 | |
97 | |
98 | //======================================================================= |
99 | //function : UReversedParameter |
100 | //purpose : |
101 | //======================================================================= |
102 | |
103 | Standard_Real Geom_ConicalSurface::UReversedParameter( const Standard_Real U) const |
104 | { |
c6541a0c |
105 | return ( 2.*M_PI - U); |
7fd59977 |
106 | } |
107 | |
108 | |
109 | //======================================================================= |
110 | //function : VReversedParameter |
111 | //purpose : |
112 | //======================================================================= |
113 | |
114 | Standard_Real Geom_ConicalSurface::VReversedParameter( const Standard_Real V) const |
115 | { |
116 | return ( -V); |
117 | } |
118 | |
119 | //======================================================================= |
120 | //function : VReverse |
121 | //purpose : |
122 | //======================================================================= |
123 | |
124 | void Geom_ConicalSurface::VReverse() |
125 | { |
126 | semiAngle = -semiAngle; |
127 | pos.ZReverse(); |
128 | } |
129 | |
130 | //======================================================================= |
131 | //function : RefRadius |
132 | //purpose : |
133 | //======================================================================= |
134 | |
135 | Standard_Real Geom_ConicalSurface::RefRadius () const |
136 | { return radius; } |
137 | |
138 | //======================================================================= |
139 | //function : SemiAngle |
140 | //purpose : |
141 | //======================================================================= |
142 | |
143 | Standard_Real Geom_ConicalSurface::SemiAngle () const |
144 | { return semiAngle;} |
145 | |
146 | //======================================================================= |
147 | //function : IsUClosed |
148 | //purpose : |
149 | //======================================================================= |
150 | |
151 | Standard_Boolean Geom_ConicalSurface::IsUClosed () const |
152 | { return Standard_True; } |
153 | |
154 | //======================================================================= |
155 | //function : IsVClosed |
156 | //purpose : |
157 | //======================================================================= |
158 | |
159 | Standard_Boolean Geom_ConicalSurface::IsVClosed () const |
160 | { return Standard_False; } |
161 | |
162 | //======================================================================= |
163 | //function : IsUPeriodic |
164 | //purpose : |
165 | //======================================================================= |
166 | |
167 | Standard_Boolean Geom_ConicalSurface::IsUPeriodic () const |
168 | { return Standard_True; } |
169 | |
170 | //======================================================================= |
171 | //function : IsVPeriodic |
172 | //purpose : |
173 | //======================================================================= |
174 | |
175 | Standard_Boolean Geom_ConicalSurface::IsVPeriodic () const |
176 | { return Standard_False; } |
177 | |
178 | //======================================================================= |
179 | //function : Cone |
180 | //purpose : |
181 | //======================================================================= |
182 | |
183 | gp_Cone Geom_ConicalSurface::Cone () const { |
184 | |
185 | return gp_Cone (pos, semiAngle, radius); |
186 | } |
187 | |
188 | |
189 | //======================================================================= |
190 | //function : SetCone |
191 | //purpose : |
192 | //======================================================================= |
193 | |
194 | void Geom_ConicalSurface::SetCone (const gp_Cone& C) { |
195 | |
196 | radius = C.RefRadius (); |
197 | semiAngle = C.SemiAngle (); |
198 | pos = C.Position (); |
199 | } |
200 | |
201 | |
202 | //======================================================================= |
203 | //function : SetRadius |
204 | //purpose : |
205 | //======================================================================= |
206 | |
207 | void Geom_ConicalSurface::SetRadius (const Standard_Real R) { |
208 | |
9775fa61 |
209 | if (R < 0.0) throw Standard_ConstructionError(); |
7fd59977 |
210 | radius = R; |
211 | } |
212 | |
213 | |
214 | //======================================================================= |
215 | //function : SetSemiAngle |
216 | //purpose : |
217 | //======================================================================= |
218 | |
219 | void Geom_ConicalSurface::SetSemiAngle (const Standard_Real Ang) { |
220 | |
c6541a0c |
221 | if (Abs(Ang) <= gp::Resolution() || Abs(Ang) >= M_PI/2.0 - gp::Resolution()) { |
9775fa61 |
222 | throw Standard_ConstructionError(); |
7fd59977 |
223 | } |
224 | semiAngle = Ang; |
225 | } |
226 | |
227 | |
228 | //======================================================================= |
229 | //function : Apex |
230 | //purpose : |
231 | //======================================================================= |
232 | |
233 | Pnt Geom_ConicalSurface::Apex () const |
234 | { |
235 | |
236 | XYZ Coord = Position().Direction().XYZ(); |
237 | Coord.Multiply (-radius / Tan (semiAngle)); |
238 | Coord.Add (Position().Location().XYZ()); |
239 | return Pnt (Coord); |
240 | } |
241 | |
242 | |
243 | //======================================================================= |
244 | //function : Bounds |
245 | //purpose : |
246 | //======================================================================= |
247 | |
248 | void Geom_ConicalSurface::Bounds (Standard_Real& U1, Standard_Real& U2, |
249 | Standard_Real& V1, Standard_Real& V2) const { |
250 | |
c6541a0c |
251 | U1 = 0.0; U2 = 2.0 * M_PI; |
7fd59977 |
252 | V1 = -Precision::Infinite(); V2 = Precision::Infinite(); |
253 | } |
254 | |
255 | |
256 | //======================================================================= |
257 | //function : Coefficients |
258 | //purpose : |
259 | //======================================================================= |
260 | |
261 | void Geom_ConicalSurface::Coefficients (Standard_Real& A1, Standard_Real& A2, Standard_Real& A3, |
262 | Standard_Real& B1, Standard_Real& B2, Standard_Real& B3, |
263 | Standard_Real& C1, Standard_Real& C2, Standard_Real& C3, |
264 | Standard_Real& D) const |
265 | { |
266 | // Dans le repere du cone : |
267 | // X**2 + Y**2 - (Myradius - Z * Tan(semiAngle))**2 = 0.0 |
268 | |
269 | Trsf T; |
270 | T.SetTransformation (pos); |
271 | Standard_Real KAng = Tan (semiAngle); |
272 | Standard_Real T11 = T.Value (1, 1); |
273 | Standard_Real T12 = T.Value (1, 2); |
274 | Standard_Real T13 = T.Value (1, 3); |
275 | Standard_Real T14 = T.Value (1, 4); |
276 | Standard_Real T21 = T.Value (2, 1); |
277 | Standard_Real T22 = T.Value (2, 2); |
278 | Standard_Real T23 = T.Value (2, 3); |
279 | Standard_Real T24 = T.Value (2, 4); |
280 | Standard_Real T31 = T.Value (3, 1) * KAng; |
281 | Standard_Real T32 = T.Value (3, 2) * KAng; |
282 | Standard_Real T33 = T.Value (3, 3) * KAng; |
283 | Standard_Real T34 = T.Value (3, 4) * KAng; |
284 | A1 = T11 * T11 + T21 * T21 - T31 * T31; |
285 | A2 = T12 * T12 + T22 * T22 - T32 * T32; |
286 | A3 = T13 * T13 + T23 * T23 - T33 * T33; |
287 | B1 = T11 * T12 + T21 * T22 - T31 * T32; |
288 | B2 = T11 * T13 + T21 * T23 - T31 * T33; |
289 | B3 = T12 * T13 + T22 * T23 - T32 * T33; |
290 | C1 = T11 * T14 + T21 * T24 + radius * T31; |
291 | C2 = T12 * T14 + T22 * T24 + radius * T32; |
292 | C3 = T13 * T14 + T23 * T24 + radius * T33; |
293 | D = T14 * T14 + T24 * T24 - radius * radius - T34 * T34 + |
294 | 2.0 * radius * T34; |
295 | } |
296 | |
297 | |
298 | |
299 | //======================================================================= |
300 | //function : D0 |
301 | //purpose : |
302 | //======================================================================= |
303 | |
304 | void Geom_ConicalSurface::D0 (const Standard_Real U, const Standard_Real V, Pnt& P) const |
305 | { |
306 | |
307 | P = ElSLib::ConeValue (U, V, pos, radius, semiAngle); |
308 | } |
309 | |
310 | |
311 | //======================================================================= |
312 | //function : D1 |
313 | //purpose : |
314 | //======================================================================= |
315 | |
316 | void Geom_ConicalSurface::D1 (const Standard_Real U , const Standard_Real V, |
317 | Pnt& P , |
318 | Vec& D1U, Vec& D1V ) const |
319 | { |
320 | ElSLib::ConeD1 (U, V, pos, radius, semiAngle, P, D1U, D1V); |
321 | } |
322 | |
323 | |
324 | //======================================================================= |
325 | //function : D2 |
326 | //purpose : |
327 | //======================================================================= |
328 | |
329 | void Geom_ConicalSurface::D2 ( const Standard_Real U , const Standard_Real V, |
330 | Pnt& P , |
331 | Vec& D1U, Vec& D1V, |
332 | Vec& D2U, Vec& D2V, Vec& D2UV) const |
333 | { |
334 | ElSLib::ConeD2 (U, V, pos, radius, semiAngle, P, D1U, D1V, |
335 | D2U, D2V, D2UV); |
336 | } |
337 | |
338 | |
339 | //======================================================================= |
340 | //function : D3 |
341 | //purpose : |
342 | //======================================================================= |
343 | |
344 | void Geom_ConicalSurface::D3 (const Standard_Real U, const Standard_Real V, |
345 | Pnt& P , |
346 | Vec& D1U , Vec& D1V, |
347 | Vec& D2U , Vec& D2V, Vec& D2UV, |
348 | Vec& D3U , Vec& D3V, Vec& D3UUV, Vec& D3UVV |
349 | ) const |
350 | { |
351 | ElSLib::ConeD3 (U, V, pos, radius, semiAngle, P, D1U, D1V, D2U, D2V, |
352 | D2UV, D3U, D3V, D3UUV, D3UVV); |
353 | } |
354 | |
355 | |
356 | //======================================================================= |
357 | //function : DN |
358 | //purpose : |
359 | //======================================================================= |
360 | |
361 | Vec Geom_ConicalSurface::DN (const Standard_Real U , const Standard_Real V, |
362 | const Standard_Integer Nu, const Standard_Integer Nv ) const |
363 | { |
364 | Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv < 0, " "); |
365 | if (Nv > 1) { return Vec (0.0, 0.0, 0.0); } |
366 | else { |
367 | return ElSLib::ConeDN (U, V, pos, radius, semiAngle, Nu, Nv); |
368 | } |
369 | } |
370 | |
371 | |
372 | //======================================================================= |
373 | //function : UIso |
374 | //purpose : |
375 | //======================================================================= |
376 | |
377 | Handle(Geom_Curve) Geom_ConicalSurface::UIso (const Standard_Real U) const |
378 | { |
379 | Handle(Geom_Line) |
380 | GL = new Geom_Line(ElSLib::ConeUIso(pos,radius,semiAngle,U)); |
381 | return GL; |
382 | } |
383 | |
384 | |
385 | //======================================================================= |
386 | //function : VIso |
387 | //purpose : |
388 | //======================================================================= |
389 | |
390 | Handle(Geom_Curve) Geom_ConicalSurface::VIso (const Standard_Real V) const |
391 | { |
392 | Handle(Geom_Circle) |
393 | GC = new Geom_Circle(ElSLib::ConeVIso(pos,radius,semiAngle,V)); |
394 | return GC; |
395 | } |
396 | |
397 | |
398 | //======================================================================= |
399 | //function : Transform |
400 | //purpose : |
401 | //======================================================================= |
402 | |
403 | void Geom_ConicalSurface::Transform (const Trsf& T) |
404 | { |
405 | radius = radius * Abs(T.ScaleFactor()); |
406 | pos.Transform (T); |
407 | } |
408 | |
409 | //======================================================================= |
410 | //function : TransformParameters |
411 | //purpose : |
412 | //======================================================================= |
413 | |
414 | void Geom_ConicalSurface::TransformParameters(Standard_Real& , |
415 | Standard_Real& V, |
416 | const gp_Trsf& T) |
417 | const |
418 | { |
419 | if (!Precision::IsInfinite(V)) V *= Abs(T.ScaleFactor()); |
420 | } |
421 | |
422 | //======================================================================= |
423 | //function : ParametricTransformation |
424 | //purpose : |
425 | //======================================================================= |
426 | |
427 | gp_GTrsf2d Geom_ConicalSurface::ParametricTransformation(const gp_Trsf& T) |
428 | const |
429 | { |
430 | gp_GTrsf2d T2; |
431 | gp_Ax2d Axis(gp::Origin2d(),gp::DX2d()); |
432 | T2.SetAffinity(Axis, Abs(T.ScaleFactor())); |
433 | return T2; |
434 | } |
435 | |