1 // Created on: 1993-03-10
3 // Copyright (c) 1993-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 <Geom_Circle.hxx>
20 #include <Geom_ConicalSurface.hxx>
21 #include <Geom_Curve.hxx>
22 #include <Geom_Geometry.hxx>
23 #include <Geom_Line.hxx>
25 #include <gp_Ax2d.hxx>
27 #include <gp_Circ.hxx>
28 #include <gp_Cone.hxx>
30 #include <gp_GTrsf2d.hxx>
32 #include <gp_Trsf.hxx>
35 #include <Precision.hxx>
36 #include <Standard_ConstructionError.hxx>
37 #include <Standard_RangeError.hxx>
38 #include <Standard_Type.hxx>
40 IMPLEMENT_STANDARD_RTTIEXT(Geom_ConicalSurface,Geom_ElementarySurface)
42 typedef Geom_ConicalSurface ConicalSurface;
54 //=======================================================================
57 //=======================================================================
59 Handle(Geom_Geometry) Geom_ConicalSurface::Copy () const {
61 Handle(Geom_ConicalSurface) Cs;
62 Cs = new ConicalSurface (pos, semiAngle, radius);
66 //=======================================================================
67 //function : Geom_ConicalSurface
69 //=======================================================================
71 Geom_ConicalSurface::Geom_ConicalSurface ( const Ax3& A3 ,
72 const Standard_Real Ang,
73 const Standard_Real R) :
74 radius(R), semiAngle (Ang)
77 if (R < 0.0 || Abs(Ang) <= gp::Resolution() || Abs(Ang) >= M_PI/2.0 - gp::Resolution())
78 throw Standard_ConstructionError();
84 //=======================================================================
85 //function : Geom_ConicalSurface
87 //=======================================================================
89 Geom_ConicalSurface::Geom_ConicalSurface ( const gp_Cone& C )
90 : radius (C.RefRadius()), semiAngle (C.SemiAngle())
96 //=======================================================================
97 //function : UReversedParameter
99 //=======================================================================
101 Standard_Real Geom_ConicalSurface::UReversedParameter( const Standard_Real U) const
103 return ( 2.*M_PI - U);
107 //=======================================================================
108 //function : VReversedParameter
110 //=======================================================================
112 Standard_Real Geom_ConicalSurface::VReversedParameter( const Standard_Real V) const
117 //=======================================================================
118 //function : VReverse
120 //=======================================================================
122 void Geom_ConicalSurface::VReverse()
124 semiAngle = -semiAngle;
128 //=======================================================================
129 //function : RefRadius
131 //=======================================================================
133 Standard_Real Geom_ConicalSurface::RefRadius () const
136 //=======================================================================
137 //function : SemiAngle
139 //=======================================================================
141 Standard_Real Geom_ConicalSurface::SemiAngle () const
144 //=======================================================================
145 //function : IsUClosed
147 //=======================================================================
149 Standard_Boolean Geom_ConicalSurface::IsUClosed () const
150 { return Standard_True; }
152 //=======================================================================
153 //function : IsVClosed
155 //=======================================================================
157 Standard_Boolean Geom_ConicalSurface::IsVClosed () const
158 { return Standard_False; }
160 //=======================================================================
161 //function : IsUPeriodic
163 //=======================================================================
165 Standard_Boolean Geom_ConicalSurface::IsUPeriodic () const
166 { return Standard_True; }
168 //=======================================================================
169 //function : IsVPeriodic
171 //=======================================================================
173 Standard_Boolean Geom_ConicalSurface::IsVPeriodic () const
174 { return Standard_False; }
176 //=======================================================================
179 //=======================================================================
181 gp_Cone Geom_ConicalSurface::Cone () const {
183 return gp_Cone (pos, semiAngle, radius);
187 //=======================================================================
190 //=======================================================================
192 void Geom_ConicalSurface::SetCone (const gp_Cone& C) {
194 radius = C.RefRadius ();
195 semiAngle = C.SemiAngle ();
200 //=======================================================================
201 //function : SetRadius
203 //=======================================================================
205 void Geom_ConicalSurface::SetRadius (const Standard_Real R) {
207 if (R < 0.0) throw Standard_ConstructionError();
212 //=======================================================================
213 //function : SetSemiAngle
215 //=======================================================================
217 void Geom_ConicalSurface::SetSemiAngle (const Standard_Real Ang) {
219 if (Abs(Ang) <= gp::Resolution() || Abs(Ang) >= M_PI/2.0 - gp::Resolution()) {
220 throw Standard_ConstructionError();
226 //=======================================================================
229 //=======================================================================
231 Pnt Geom_ConicalSurface::Apex () const
234 XYZ Coord = Position().Direction().XYZ();
235 Coord.Multiply (-radius / Tan (semiAngle));
236 Coord.Add (Position().Location().XYZ());
241 //=======================================================================
244 //=======================================================================
246 void Geom_ConicalSurface::Bounds (Standard_Real& U1, Standard_Real& U2,
247 Standard_Real& V1, Standard_Real& V2) const {
249 U1 = 0.0; U2 = 2.0 * M_PI;
250 V1 = -Precision::Infinite(); V2 = Precision::Infinite();
254 //=======================================================================
255 //function : Coefficients
257 //=======================================================================
259 void Geom_ConicalSurface::Coefficients (Standard_Real& A1, Standard_Real& A2, Standard_Real& A3,
260 Standard_Real& B1, Standard_Real& B2, Standard_Real& B3,
261 Standard_Real& C1, Standard_Real& C2, Standard_Real& C3,
262 Standard_Real& D) const
264 // Dans le repere du cone :
265 // X**2 + Y**2 - (Myradius - Z * Tan(semiAngle))**2 = 0.0
268 T.SetTransformation (pos);
269 Standard_Real KAng = Tan (semiAngle);
270 Standard_Real T11 = T.Value (1, 1);
271 Standard_Real T12 = T.Value (1, 2);
272 Standard_Real T13 = T.Value (1, 3);
273 Standard_Real T14 = T.Value (1, 4);
274 Standard_Real T21 = T.Value (2, 1);
275 Standard_Real T22 = T.Value (2, 2);
276 Standard_Real T23 = T.Value (2, 3);
277 Standard_Real T24 = T.Value (2, 4);
278 Standard_Real T31 = T.Value (3, 1) * KAng;
279 Standard_Real T32 = T.Value (3, 2) * KAng;
280 Standard_Real T33 = T.Value (3, 3) * KAng;
281 Standard_Real T34 = T.Value (3, 4) * KAng;
282 A1 = T11 * T11 + T21 * T21 - T31 * T31;
283 A2 = T12 * T12 + T22 * T22 - T32 * T32;
284 A3 = T13 * T13 + T23 * T23 - T33 * T33;
285 B1 = T11 * T12 + T21 * T22 - T31 * T32;
286 B2 = T11 * T13 + T21 * T23 - T31 * T33;
287 B3 = T12 * T13 + T22 * T23 - T32 * T33;
288 C1 = T11 * T14 + T21 * T24 + radius * T31;
289 C2 = T12 * T14 + T22 * T24 + radius * T32;
290 C3 = T13 * T14 + T23 * T24 + radius * T33;
291 D = T14 * T14 + T24 * T24 - radius * radius - T34 * T34 +
297 //=======================================================================
300 //=======================================================================
302 void Geom_ConicalSurface::D0 (const Standard_Real U, const Standard_Real V, Pnt& P) const
305 P = ElSLib::ConeValue (U, V, pos, radius, semiAngle);
309 //=======================================================================
312 //=======================================================================
314 void Geom_ConicalSurface::D1 (const Standard_Real U , const Standard_Real V,
316 Vec& D1U, Vec& D1V ) const
318 ElSLib::ConeD1 (U, V, pos, radius, semiAngle, P, D1U, D1V);
322 //=======================================================================
325 //=======================================================================
327 void Geom_ConicalSurface::D2 ( const Standard_Real U , const Standard_Real V,
330 Vec& D2U, Vec& D2V, Vec& D2UV) const
332 ElSLib::ConeD2 (U, V, pos, radius, semiAngle, P, D1U, D1V,
337 //=======================================================================
340 //=======================================================================
342 void Geom_ConicalSurface::D3 (const Standard_Real U, const Standard_Real V,
345 Vec& D2U , Vec& D2V, Vec& D2UV,
346 Vec& D3U , Vec& D3V, Vec& D3UUV, Vec& D3UVV
349 ElSLib::ConeD3 (U, V, pos, radius, semiAngle, P, D1U, D1V, D2U, D2V,
350 D2UV, D3U, D3V, D3UUV, D3UVV);
354 //=======================================================================
357 //=======================================================================
359 Vec Geom_ConicalSurface::DN (const Standard_Real U , const Standard_Real V,
360 const Standard_Integer Nu, const Standard_Integer Nv ) const
362 Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv < 0, " ");
363 if (Nv > 1) { return Vec (0.0, 0.0, 0.0); }
365 return ElSLib::ConeDN (U, V, pos, radius, semiAngle, Nu, Nv);
370 //=======================================================================
373 //=======================================================================
375 Handle(Geom_Curve) Geom_ConicalSurface::UIso (const Standard_Real U) const
378 GL = new Geom_Line(ElSLib::ConeUIso(pos,radius,semiAngle,U));
383 //=======================================================================
386 //=======================================================================
388 Handle(Geom_Curve) Geom_ConicalSurface::VIso (const Standard_Real V) const
391 GC = new Geom_Circle(ElSLib::ConeVIso(pos,radius,semiAngle,V));
396 //=======================================================================
397 //function : Transform
399 //=======================================================================
401 void Geom_ConicalSurface::Transform (const Trsf& T)
403 radius = radius * Abs(T.ScaleFactor());
407 //=======================================================================
408 //function : TransformParameters
410 //=======================================================================
412 void Geom_ConicalSurface::TransformParameters(Standard_Real& ,
417 if (!Precision::IsInfinite(V)) V *= Abs(T.ScaleFactor());
420 //=======================================================================
421 //function : ParametricTransformation
423 //=======================================================================
425 gp_GTrsf2d Geom_ConicalSurface::ParametricTransformation(const gp_Trsf& T)
429 gp_Ax2d Axis(gp::Origin2d(),gp::DX2d());
430 T2.SetAffinity(Axis, Abs(T.ScaleFactor()));
434 //=======================================================================
435 //function : DumpJson
437 //=======================================================================
438 void Geom_ConicalSurface::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
440 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
442 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Geom_ElementarySurface)
444 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, radius)
445 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, semiAngle)