summaryrefslogtreecommitdiff
path: root/src/BRepPrim/BRepPrim_Cone.cxx
blob: ae02c93e338608c70740935fbdd113efbfa9e5fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// File:	BRepPrim_Cone.cxx
// Created:	Fri Nov  6 11:33:55 1992
// Author:	Remi LEQUETTE
//		<rle@phylox>



#include <BRepPrim_Cone.ixx>
#include <gp.hxx>
#include <gp_Vec.hxx>
#include <Precision.hxx>
#include <Geom_ConicalSurface.hxx>
#include <Geom_Line.hxx>
#include <Geom2d_Line.hxx>
#include <Standard_DomainError.hxx>

//=======================================================================
//function : BRepPrim_Cone
//purpose  : 
//=======================================================================

BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle, 
			     const gp_Ax2& Position, 
			     const Standard_Real Height, 
			     const Standard_Real Radius) :
       BRepPrim_Revolution(Position,0,0),
       myHalfAngle(Angle),
       myRadius(Radius)
{
  if (Height < Precision::Confusion())
    Standard_DomainError::Raise("cone with null height");
  if (myHalfAngle*Height < Precision::Confusion())
    Standard_DomainError::Raise("cone with null angle");
  if ((PI/2 - myHalfAngle)*Height < Precision::Confusion())
    Standard_DomainError::Raise("cone with angle > PI/2");
  
  // cut at top
  VMax(Height / Cos(myHalfAngle));
  VMin(0.);
  SetMeridian();
}

//=======================================================================
//function : BRepPrim_Cone
//purpose  : 
//=======================================================================

BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle) :
       BRepPrim_Revolution(gp::XOY(),0,RealLast()),
       myHalfAngle(Angle),
       myRadius(0.)
{
  if ((Angle < 0) || (Angle > PI/2)) 
    Standard_DomainError::Raise("cone with angle <0 or > PI/2");
  VMin(0.);
  SetMeridian();
}

//=======================================================================
//function : BRepPrim_Cone
//purpose  : 
//=======================================================================

BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle, 
			     const gp_Pnt& Apex) :
       BRepPrim_Revolution(gp_Ax2(Apex,gp_Dir(0,0,1),gp_Dir(1,0,0)),
			   0,RealLast()),
       myHalfAngle(Angle),
       myRadius(0.)
{
  if ((Angle < 0) || (Angle > PI/2)) 
    Standard_DomainError::Raise("cone with angle <0 or > PI/2");
  VMin(0.);
  SetMeridian();
}

//=======================================================================
//function : BRepPrim_Cone
//purpose  : 
//=======================================================================

BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle,
			     const gp_Ax2& Axes) :
       BRepPrim_Revolution( Axes, 0,RealLast()),
       myHalfAngle(Angle)
{
  if ((Angle < 0) || (Angle > PI/2)) 
    Standard_DomainError::Raise("cone with angle <0 or > PI/2");
  VMin(0.);
  SetMeridian();
}

//=======================================================================
//function : BRepPrim_Cone
//purpose  : 
//=======================================================================

BRepPrim_Cone::BRepPrim_Cone(const Standard_Real R1,
			     const Standard_Real R2,
			     const Standard_Real H) :
       BRepPrim_Revolution(gp::XOY(),0,0)
{
  SetParameters(R1,R2,H);
  SetMeridian();
}

//=======================================================================
//function : BRepPrim_Cone
//purpose  : 
//=======================================================================

BRepPrim_Cone::BRepPrim_Cone(const gp_Pnt& Center,
			     const Standard_Real R1, 
			     const Standard_Real R2,
			     const Standard_Real H) :
       BRepPrim_Revolution(gp_Ax2(Center,gp_Dir(0,0,1),gp_Dir(1,0,0)),
			   0,0)
{
  SetParameters(R1,R2,H);
  SetMeridian();
}

//=======================================================================
//function : BRepPrim_Cone
//purpose  : 
//=======================================================================

BRepPrim_Cone::BRepPrim_Cone(const gp_Ax2& Axes, 
			     const Standard_Real R1, 
			     const Standard_Real R2, 
			     const Standard_Real H) :
       BRepPrim_Revolution(Axes,0,0)
{
  SetParameters(R1,R2,H);
  SetMeridian();
}

//=======================================================================
//function : MakeEmptyLateralFace
//purpose  : 
//=======================================================================

TopoDS_Face  BRepPrim_Cone::MakeEmptyLateralFace()const 
{
  Handle(Geom_ConicalSurface) C =
    new Geom_ConicalSurface(Axes(),myHalfAngle,myRadius);
  TopoDS_Face F;
  myBuilder.Builder().MakeFace(F,C,Precision::Confusion());
  return F;
}

//=======================================================================
//function : SetMeridian
//purpose  : 
//=======================================================================

void BRepPrim_Cone::SetMeridian ()
{
  gp_Ax1 A = Axes().Axis();
  A.Rotate(gp_Ax1(Axes().Location(),Axes().YDirection()),myHalfAngle);
  gp_Vec V(Axes().XDirection());
  V *= myRadius;
  A.Translate(V);
  Handle(Geom_Line) L = new Geom_Line(A);
  Handle(Geom2d_Line) L2d = 
    new Geom2d_Line(gp_Pnt2d(myRadius,0),gp_Dir2d(Sin(myHalfAngle),Cos(myHalfAngle)));
  Meridian(L,L2d);
}

//=======================================================================
//function : SetParameters
//purpose  : 
//=======================================================================

void BRepPrim_Cone::SetParameters(const Standard_Real R1,
				  const Standard_Real R2,
				  const Standard_Real H)
{
  if (((R1 != 0) && (R1 < Precision::Confusion())) ||
      ((R2 != 0) && (R2 < Precision::Confusion())))
    Standard_DomainError::Raise("cone with negative or too small radius");
  if (Abs(R1-R2) < Precision::Confusion())
    Standard_DomainError::Raise("cone with two identic radii");
  if (H < Precision::Confusion())
    Standard_DomainError::Raise("cone with negative or null height");

  myRadius = R1;
  myHalfAngle = ATan((R2 - R1) / H);

  // cut top and bottom
  VMin(0.);
  VMax(Sqrt(H*H + (R2-R1)*(R2-R1)));
}