b311480e |
1 | // Created on: 1992-11-06 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1992-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 <BRepPrim_Cone.ixx> |
18 | #include <gp.hxx> |
19 | #include <gp_Vec.hxx> |
20 | #include <Precision.hxx> |
21 | #include <Geom_ConicalSurface.hxx> |
22 | #include <Geom_Line.hxx> |
23 | #include <Geom2d_Line.hxx> |
24 | #include <Standard_DomainError.hxx> |
25 | |
26 | //======================================================================= |
27 | //function : BRepPrim_Cone |
28 | //purpose : |
29 | //======================================================================= |
30 | |
31 | BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle, |
32 | const gp_Ax2& Position, |
33 | const Standard_Real Height, |
34 | const Standard_Real Radius) : |
35 | BRepPrim_Revolution(Position,0,0), |
36 | myHalfAngle(Angle), |
37 | myRadius(Radius) |
38 | { |
39 | if (Height < Precision::Confusion()) |
40 | Standard_DomainError::Raise("cone with null height"); |
41 | if (myHalfAngle*Height < Precision::Confusion()) |
42 | Standard_DomainError::Raise("cone with null angle"); |
c6541a0c |
43 | if ((M_PI/2 - myHalfAngle)*Height < Precision::Confusion()) |
7fd59977 |
44 | Standard_DomainError::Raise("cone with angle > PI/2"); |
45 | |
46 | // cut at top |
47 | VMax(Height / Cos(myHalfAngle)); |
48 | VMin(0.); |
49 | SetMeridian(); |
50 | } |
51 | |
52 | //======================================================================= |
53 | //function : BRepPrim_Cone |
54 | //purpose : |
55 | //======================================================================= |
56 | |
57 | BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle) : |
58 | BRepPrim_Revolution(gp::XOY(),0,RealLast()), |
59 | myHalfAngle(Angle), |
60 | myRadius(0.) |
61 | { |
c6541a0c |
62 | if ((Angle < 0) || (Angle > M_PI/2)) |
7fd59977 |
63 | Standard_DomainError::Raise("cone with angle <0 or > PI/2"); |
64 | VMin(0.); |
65 | SetMeridian(); |
66 | } |
67 | |
68 | //======================================================================= |
69 | //function : BRepPrim_Cone |
70 | //purpose : |
71 | //======================================================================= |
72 | |
73 | BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle, |
74 | const gp_Pnt& Apex) : |
75 | BRepPrim_Revolution(gp_Ax2(Apex,gp_Dir(0,0,1),gp_Dir(1,0,0)), |
76 | 0,RealLast()), |
77 | myHalfAngle(Angle), |
78 | myRadius(0.) |
79 | { |
c6541a0c |
80 | if ((Angle < 0) || (Angle > M_PI/2)) |
7fd59977 |
81 | Standard_DomainError::Raise("cone with angle <0 or > PI/2"); |
82 | VMin(0.); |
83 | SetMeridian(); |
84 | } |
85 | |
86 | //======================================================================= |
87 | //function : BRepPrim_Cone |
88 | //purpose : |
89 | //======================================================================= |
90 | |
91 | BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle, |
92 | const gp_Ax2& Axes) : |
93 | BRepPrim_Revolution( Axes, 0,RealLast()), |
94 | myHalfAngle(Angle) |
95 | { |
c6541a0c |
96 | if ((Angle < 0) || (Angle > M_PI/2)) |
7fd59977 |
97 | Standard_DomainError::Raise("cone with angle <0 or > PI/2"); |
98 | VMin(0.); |
99 | SetMeridian(); |
100 | } |
101 | |
102 | //======================================================================= |
103 | //function : BRepPrim_Cone |
104 | //purpose : |
105 | //======================================================================= |
106 | |
107 | BRepPrim_Cone::BRepPrim_Cone(const Standard_Real R1, |
108 | const Standard_Real R2, |
109 | const Standard_Real H) : |
110 | BRepPrim_Revolution(gp::XOY(),0,0) |
111 | { |
112 | SetParameters(R1,R2,H); |
113 | SetMeridian(); |
114 | } |
115 | |
116 | //======================================================================= |
117 | //function : BRepPrim_Cone |
118 | //purpose : |
119 | //======================================================================= |
120 | |
121 | BRepPrim_Cone::BRepPrim_Cone(const gp_Pnt& Center, |
122 | const Standard_Real R1, |
123 | const Standard_Real R2, |
124 | const Standard_Real H) : |
125 | BRepPrim_Revolution(gp_Ax2(Center,gp_Dir(0,0,1),gp_Dir(1,0,0)), |
126 | 0,0) |
127 | { |
128 | SetParameters(R1,R2,H); |
129 | SetMeridian(); |
130 | } |
131 | |
132 | //======================================================================= |
133 | //function : BRepPrim_Cone |
134 | //purpose : |
135 | //======================================================================= |
136 | |
137 | BRepPrim_Cone::BRepPrim_Cone(const gp_Ax2& Axes, |
138 | const Standard_Real R1, |
139 | const Standard_Real R2, |
140 | const Standard_Real H) : |
141 | BRepPrim_Revolution(Axes,0,0) |
142 | { |
143 | SetParameters(R1,R2,H); |
144 | SetMeridian(); |
145 | } |
146 | |
147 | //======================================================================= |
148 | //function : MakeEmptyLateralFace |
149 | //purpose : |
150 | //======================================================================= |
151 | |
152 | TopoDS_Face BRepPrim_Cone::MakeEmptyLateralFace()const |
153 | { |
154 | Handle(Geom_ConicalSurface) C = |
155 | new Geom_ConicalSurface(Axes(),myHalfAngle,myRadius); |
156 | TopoDS_Face F; |
157 | myBuilder.Builder().MakeFace(F,C,Precision::Confusion()); |
158 | return F; |
159 | } |
160 | |
161 | //======================================================================= |
162 | //function : SetMeridian |
163 | //purpose : |
164 | //======================================================================= |
165 | |
166 | void BRepPrim_Cone::SetMeridian () |
167 | { |
168 | gp_Ax1 A = Axes().Axis(); |
169 | A.Rotate(gp_Ax1(Axes().Location(),Axes().YDirection()),myHalfAngle); |
170 | gp_Vec V(Axes().XDirection()); |
171 | V *= myRadius; |
172 | A.Translate(V); |
173 | Handle(Geom_Line) L = new Geom_Line(A); |
174 | Handle(Geom2d_Line) L2d = |
175 | new Geom2d_Line(gp_Pnt2d(myRadius,0),gp_Dir2d(Sin(myHalfAngle),Cos(myHalfAngle))); |
176 | Meridian(L,L2d); |
177 | } |
178 | |
179 | //======================================================================= |
180 | //function : SetParameters |
181 | //purpose : |
182 | //======================================================================= |
183 | |
184 | void BRepPrim_Cone::SetParameters(const Standard_Real R1, |
185 | const Standard_Real R2, |
186 | const Standard_Real H) |
187 | { |
188 | if (((R1 != 0) && (R1 < Precision::Confusion())) || |
189 | ((R2 != 0) && (R2 < Precision::Confusion()))) |
190 | Standard_DomainError::Raise("cone with negative or too small radius"); |
191 | if (Abs(R1-R2) < Precision::Confusion()) |
192 | Standard_DomainError::Raise("cone with two identic radii"); |
193 | if (H < Precision::Confusion()) |
194 | Standard_DomainError::Raise("cone with negative or null height"); |
195 | |
196 | myRadius = R1; |
197 | myHalfAngle = ATan((R2 - R1) / H); |
198 | |
199 | // cut top and bottom |
200 | VMin(0.); |
201 | VMax(Sqrt(H*H + (R2-R1)*(R2-R1))); |
202 | } |
203 | |
204 | |