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