1 // Created on: 1992-11-06
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1992-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.
18 #include <BRepPrim_Cone.hxx>
19 #include <Geom2d_Line.hxx>
20 #include <Geom_ConicalSurface.hxx>
21 #include <Geom_Line.hxx>
26 #include <Precision.hxx>
27 #include <Standard_DomainError.hxx>
28 #include <TopoDS_Face.hxx>
30 //=======================================================================
31 //function : BRepPrim_Cone
33 //=======================================================================
34 BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle,
35 const gp_Ax2& Position,
36 const Standard_Real Height,
37 const Standard_Real Radius) :
38 BRepPrim_Revolution(Position,0,0),
42 if (Height < Precision::Confusion())
43 throw Standard_DomainError("cone with null height");
44 if (myHalfAngle*Height < Precision::Confusion())
45 throw Standard_DomainError("cone with null angle");
46 if ((M_PI/2 - myHalfAngle)*Height < Precision::Confusion())
47 throw Standard_DomainError("cone with angle > PI/2");
50 VMax(Height / Cos(myHalfAngle));
55 //=======================================================================
56 //function : BRepPrim_Cone
58 //=======================================================================
60 BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle) :
61 BRepPrim_Revolution(gp::XOY(),0,RealLast()),
65 if ((Angle < 0) || (Angle > M_PI/2))
66 throw Standard_DomainError("cone with angle <0 or > PI/2");
71 //=======================================================================
72 //function : BRepPrim_Cone
74 //=======================================================================
76 BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle,
78 BRepPrim_Revolution(gp_Ax2(Apex,gp_Dir(0,0,1),gp_Dir(1,0,0)),
83 if ((Angle < 0) || (Angle > M_PI/2))
84 throw Standard_DomainError("cone with angle <0 or > PI/2");
89 //=======================================================================
90 //function : BRepPrim_Cone
92 //=======================================================================
94 BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle,
96 BRepPrim_Revolution( Axes, 0,RealLast()),
99 if ((Angle < 0) || (Angle > M_PI/2))
100 throw Standard_DomainError("cone with angle <0 or > PI/2");
105 //=======================================================================
106 //function : BRepPrim_Cone
108 //=======================================================================
110 BRepPrim_Cone::BRepPrim_Cone(const Standard_Real R1,
111 const Standard_Real R2,
112 const Standard_Real H) :
113 BRepPrim_Revolution(gp::XOY(),0,0)
115 SetParameters(R1,R2,H);
119 //=======================================================================
120 //function : BRepPrim_Cone
122 //=======================================================================
124 BRepPrim_Cone::BRepPrim_Cone(const gp_Pnt& Center,
125 const Standard_Real R1,
126 const Standard_Real R2,
127 const Standard_Real H) :
128 BRepPrim_Revolution(gp_Ax2(Center,gp_Dir(0,0,1),gp_Dir(1,0,0)),
131 SetParameters(R1,R2,H);
135 //=======================================================================
136 //function : BRepPrim_Cone
138 //=======================================================================
140 BRepPrim_Cone::BRepPrim_Cone(const gp_Ax2& Axes,
141 const Standard_Real R1,
142 const Standard_Real R2,
143 const Standard_Real H) :
144 BRepPrim_Revolution(Axes,0,0)
146 SetParameters(R1,R2,H);
150 //=======================================================================
151 //function : MakeEmptyLateralFace
153 //=======================================================================
155 TopoDS_Face BRepPrim_Cone::MakeEmptyLateralFace()const
157 Handle(Geom_ConicalSurface) C =
158 new Geom_ConicalSurface(Axes(),myHalfAngle,myRadius);
160 myBuilder.Builder().MakeFace(F,C,Precision::Confusion());
164 //=======================================================================
165 //function : SetMeridian
167 //=======================================================================
169 void BRepPrim_Cone::SetMeridian ()
171 gp_Ax1 A = Axes().Axis();
172 A.Rotate(gp_Ax1(Axes().Location(),Axes().YDirection()),myHalfAngle);
173 gp_Vec V(Axes().XDirection());
176 Handle(Geom_Line) L = new Geom_Line(A);
177 Handle(Geom2d_Line) L2d =
178 new Geom2d_Line(gp_Pnt2d(myRadius,0),gp_Dir2d(Sin(myHalfAngle),Cos(myHalfAngle)));
182 //=======================================================================
183 //function : SetParameters
185 //=======================================================================
187 void BRepPrim_Cone::SetParameters(const Standard_Real R1,
188 const Standard_Real R2,
189 const Standard_Real H)
191 if (((R1 != 0) && (R1 < Precision::Confusion())) ||
192 ((R2 != 0) && (R2 < Precision::Confusion())))
193 throw Standard_DomainError("cone with negative or too small radius");
194 if (Abs(R1-R2) < Precision::Confusion())
195 throw Standard_DomainError("cone with two identic radii");
196 if (H < Precision::Confusion())
197 throw Standard_DomainError("cone with negative or null height");
200 myHalfAngle = ATan((R2 - R1) / H);
202 // cut top and bottom
204 VMax(Sqrt(H*H + (R2-R1)*(R2-R1)));