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>
24 #include <GeomAbs_UVSense.hxx>
26 #include <gp_Ax2d.hxx>
28 #include <gp_Circ.hxx>
29 #include <gp_Cone.hxx>
31 #include <gp_GTrsf2d.hxx>
34 #include <gp_Trsf.hxx>
37 #include <Precision.hxx>
38 #include <Standard_ConstructionError.hxx>
39 #include <Standard_RangeError.hxx>
40 #include <Standard_Type.hxx>
42 IMPLEMENT_STANDARD_RTTIEXT(Geom_ConicalSurface,Geom_ElementarySurface)
44 typedef Geom_ConicalSurface ConicalSurface;
56 //=======================================================================
59 //=======================================================================
61 Handle(Geom_Geometry) Geom_ConicalSurface::Copy () const {
63 Handle(Geom_ConicalSurface) Cs;
64 Cs = new ConicalSurface (pos, semiAngle, radius);
68 //=======================================================================
69 //function : Geom_ConicalSurface
71 //=======================================================================
73 Geom_ConicalSurface::Geom_ConicalSurface ( const Ax3& A3 ,
74 const Standard_Real Ang,
75 const Standard_Real R) :
76 radius(R), semiAngle (Ang)
79 if (R < 0.0 || Abs(Ang) <= gp::Resolution() || Abs(Ang) >= M_PI/2.0 - gp::Resolution())
80 throw Standard_ConstructionError();
86 //=======================================================================
87 //function : Geom_ConicalSurface
89 //=======================================================================
91 Geom_ConicalSurface::Geom_ConicalSurface ( const gp_Cone& C )
92 : radius (C.RefRadius()), semiAngle (C.SemiAngle())
98 //=======================================================================
99 //function : UReversedParameter
101 //=======================================================================
103 Standard_Real Geom_ConicalSurface::UReversedParameter( const Standard_Real U) const
105 return ( 2.*M_PI - U);
109 //=======================================================================
110 //function : VReversedParameter
112 //=======================================================================
114 Standard_Real Geom_ConicalSurface::VReversedParameter( const Standard_Real V) const
119 //=======================================================================
120 //function : VReverse
122 //=======================================================================
124 void Geom_ConicalSurface::VReverse()
126 semiAngle = -semiAngle;
130 //=======================================================================
131 //function : RefRadius
133 //=======================================================================
135 Standard_Real Geom_ConicalSurface::RefRadius () const
138 //=======================================================================
139 //function : SemiAngle
141 //=======================================================================
143 Standard_Real Geom_ConicalSurface::SemiAngle () const
146 //=======================================================================
147 //function : IsUClosed
149 //=======================================================================
151 Standard_Boolean Geom_ConicalSurface::IsUClosed () const
152 { return Standard_True; }
154 //=======================================================================
155 //function : IsVClosed
157 //=======================================================================
159 Standard_Boolean Geom_ConicalSurface::IsVClosed () const
160 { return Standard_False; }
162 //=======================================================================
163 //function : IsUPeriodic
165 //=======================================================================
167 Standard_Boolean Geom_ConicalSurface::IsUPeriodic () const
168 { return Standard_True; }
170 //=======================================================================
171 //function : IsVPeriodic
173 //=======================================================================
175 Standard_Boolean Geom_ConicalSurface::IsVPeriodic () const
176 { return Standard_False; }
178 //=======================================================================
181 //=======================================================================
183 gp_Cone Geom_ConicalSurface::Cone () const {
185 return gp_Cone (pos, semiAngle, radius);
189 //=======================================================================
192 //=======================================================================
194 void Geom_ConicalSurface::SetCone (const gp_Cone& C) {
196 radius = C.RefRadius ();
197 semiAngle = C.SemiAngle ();
202 //=======================================================================
203 //function : SetRadius
205 //=======================================================================
207 void Geom_ConicalSurface::SetRadius (const Standard_Real R) {
209 if (R < 0.0) throw Standard_ConstructionError();
214 //=======================================================================
215 //function : SetSemiAngle
217 //=======================================================================
219 void Geom_ConicalSurface::SetSemiAngle (const Standard_Real Ang) {
221 if (Abs(Ang) <= gp::Resolution() || Abs(Ang) >= M_PI/2.0 - gp::Resolution()) {
222 throw Standard_ConstructionError();
228 //=======================================================================
231 //=======================================================================
233 Pnt Geom_ConicalSurface::Apex () const
236 XYZ Coord = Position().Direction().XYZ();
237 Coord.Multiply (-radius / Tan (semiAngle));
238 Coord.Add (Position().Location().XYZ());
243 //=======================================================================
246 //=======================================================================
248 void Geom_ConicalSurface::Bounds (Standard_Real& U1, Standard_Real& U2,
249 Standard_Real& V1, Standard_Real& V2) const {
251 U1 = 0.0; U2 = 2.0 * M_PI;
252 V1 = -Precision::Infinite(); V2 = Precision::Infinite();
256 //=======================================================================
257 //function : Coefficients
259 //=======================================================================
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
266 // Dans le repere du cone :
267 // X**2 + Y**2 - (Myradius - Z * Tan(semiAngle))**2 = 0.0
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 +
299 //=======================================================================
302 //=======================================================================
304 void Geom_ConicalSurface::D0 (const Standard_Real U, const Standard_Real V, Pnt& P) const
307 P = ElSLib::ConeValue (U, V, pos, radius, semiAngle);
311 //=======================================================================
314 //=======================================================================
316 void Geom_ConicalSurface::D1 (const Standard_Real U , const Standard_Real V,
318 Vec& D1U, Vec& D1V ) const
320 ElSLib::ConeD1 (U, V, pos, radius, semiAngle, P, D1U, D1V);
324 //=======================================================================
327 //=======================================================================
329 void Geom_ConicalSurface::D2 ( const Standard_Real U , const Standard_Real V,
332 Vec& D2U, Vec& D2V, Vec& D2UV) const
334 ElSLib::ConeD2 (U, V, pos, radius, semiAngle, P, D1U, D1V,
339 //=======================================================================
342 //=======================================================================
344 void Geom_ConicalSurface::D3 (const Standard_Real U, const Standard_Real V,
347 Vec& D2U , Vec& D2V, Vec& D2UV,
348 Vec& D3U , Vec& D3V, Vec& D3UUV, Vec& D3UVV
351 ElSLib::ConeD3 (U, V, pos, radius, semiAngle, P, D1U, D1V, D2U, D2V,
352 D2UV, D3U, D3V, D3UUV, D3UVV);
356 //=======================================================================
359 //=======================================================================
361 Vec Geom_ConicalSurface::DN (const Standard_Real U , const Standard_Real V,
362 const Standard_Integer Nu, const Standard_Integer Nv ) const
364 Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv < 0, " ");
365 if (Nv > 1) { return Vec (0.0, 0.0, 0.0); }
367 return ElSLib::ConeDN (U, V, pos, radius, semiAngle, Nu, Nv);
372 //=======================================================================
375 //=======================================================================
377 Handle(Geom_Curve) Geom_ConicalSurface::UIso (const Standard_Real U) const
380 GL = new Geom_Line(ElSLib::ConeUIso(pos,radius,semiAngle,U));
385 //=======================================================================
388 //=======================================================================
390 Handle(Geom_Curve) Geom_ConicalSurface::VIso (const Standard_Real V) const
393 GC = new Geom_Circle(ElSLib::ConeVIso(pos,radius,semiAngle,V));
398 //=======================================================================
399 //function : Transform
401 //=======================================================================
403 void Geom_ConicalSurface::Transform (const Trsf& T)
405 radius = radius * Abs(T.ScaleFactor());
409 //=======================================================================
410 //function : TransformParameters
412 //=======================================================================
414 void Geom_ConicalSurface::TransformParameters(Standard_Real& ,
419 if (!Precision::IsInfinite(V)) V *= Abs(T.ScaleFactor());
422 //=======================================================================
423 //function : ParametricTransformation
425 //=======================================================================
427 gp_GTrsf2d Geom_ConicalSurface::ParametricTransformation(const gp_Trsf& T)
431 gp_Ax2d Axis(gp::Origin2d(),gp::DX2d());
432 T2.SetAffinity(Axis, Abs(T.ScaleFactor()));
436 //=======================================================================
437 //function : DumpJson
439 //=======================================================================
440 void Geom_ConicalSurface::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
442 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
444 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Geom_ElementarySurface)
446 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, radius)
447 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, semiAngle)