summaryrefslogtreecommitdiff
path: root/src/gce/gce_MakeCone.cxx
blob: 566bdd715e09e4097654def8f173f7864d4f5116 (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
196
197
198
199
200
201
202
203
// File:	gce_MakeCirc.cxx
// Created:	Wed Sep  2 10:34:28 1992
// Author:	Remi GILET
//		<reg@sdsun1>

#include <gce_MakeCone.ixx>
#include <StdFail_NotDone.hxx>
#include <gp.hxx>

//=========================================================================
//  Construction d un cone par son axe , le rayon de sa base et le demi   +
//  angle d ouverture.                                                    +
//=========================================================================

gce_MakeCone::gce_MakeCone(const gp_Ax2&       A2    ,
			   const Standard_Real Ang   ,
			   const Standard_Real Radius)
{
  if (Radius < 0.0) { TheError = gce_NegativeRadius; }
  else {
    if (Ang <= gp::Resolution() || PI/2-Ang <= gp::Resolution()) {
      TheError = gce_BadAngle;
    }
    else {
      TheError = gce_Done;
      TheCone = gp_Cone(A2,Ang,Radius);
    }
  }
}

//=========================================================================
//  Constructions d un cone de gp par quatre points P1, P2, P3 et P4.     +
//  P1 et P2 donnent l axe du cone, la distance de P3 a l axe donne       +
//  le rayon de la base du cone et la distance de P4 a l axe donne le     +
//  rayon du cone pour la section passant par P4.                         +
//=========================================================================

gce_MakeCone::gce_MakeCone(const gp_Pnt& P1 ,
			   const gp_Pnt& P2 ,
			   const gp_Pnt& P3 ,
			   const gp_Pnt& P4 ) 
{
  if (P1.Distance(P2)<RealEpsilon() || P3.Distance(P4)<RealEpsilon()) { TheError = gce_ConfusedPoints; return;  }

  gp_Dir D1(P2.XYZ()-P1.XYZ());
  Standard_Real cos = D1.Dot(gp_Dir(P4.XYZ()-P1.XYZ()));
  Standard_Real dist = P1.Distance(P4);
  gp_Pnt PP4(P1.XYZ()+cos*dist*D1.XYZ());
  cos = D1.Dot(gp_Dir(P3.XYZ()-P1.XYZ()));
  dist = P1.Distance(P3);
  gp_Pnt PP3(P1.XYZ()+cos*dist*D1.XYZ());
  
  Standard_Real Dist13 = PP3.Distance(P1);
  Standard_Real Dist14 = PP4.Distance(P1);
  if(Abs(Dist13-Dist14)<RealEpsilon()) { TheError = gce_NullAngle;  return; }
  gp_Lin L1(P1,D1);
  Standard_Real Dist3 = L1.Distance(P3);
  Standard_Real Dist4 = L1.Distance(P4);
  Standard_Real DifRad = Dist3-Dist4;
  Standard_Real angle = Abs(ATan(DifRad/(Dist13-Dist14)));
  if(Abs(PI/2.-angle) < RealEpsilon() || Abs(angle) < RealEpsilon()) { TheError = gce_NullRadius; return; }
  Standard_Real R1 = PP3.Distance(P3);
  Standard_Real R2 = PP4.Distance(P4);
  if (R1 < 0.0 || R2 < 0.0) { TheError = gce_NegativeRadius; return; }
  gp_Dir DD1(PP4.XYZ()-PP3.XYZ());
  gp_Dir D2;
  Standard_Real x = DD1.X();
  Standard_Real y = DD1.Y();
  Standard_Real z = DD1.Z();
  if (Abs(x) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
  else if (Abs(y) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
  else if (Abs(z) > gp::Resolution()) { D2 = gp_Dir(0.0,-z,y); }
  if (R1 > R2) { angle *= -1; }
  TheCone = gp_Cone(gp_Ax2(PP3,DD1,D2),angle,R1);
  TheError = gce_Done;
}
 
 

//=========================================================================
//  Constructions d un cone de gp par son axe et deux points P1, P2.      +
//  La distance de P1 a l axe donne le rayon de la base du cone et la     +
//  distance de P2 a l axe donne le rayon du cone pour la section passant +
//  par P2.                                                               +
//=========================================================================

gce_MakeCone::gce_MakeCone(const gp_Ax1&   Axis  ,
			   const gp_Pnt&   P1    ,
			   const gp_Pnt&   P2    ) 
{
  gp_Pnt P3(Axis.Location());
  gp_Pnt P4(P3.XYZ()+Axis.Direction().XYZ());
  gce_MakeCone Cone(P3,P4,P1,P2);
  if (Cone.IsDone()) {
    TheCone = Cone.Value();
    TheError = gce_Done;
  }
  else { 
    TheError = Cone.Status();
  }
}

//=========================================================================
//  Constructions d un cone parallele a un autre cone passant par un      +
//  donne.                                                                +
//=========================================================================

//gce_MakeCone::gce_MakeCone(const gp_Cone&  cone ,
//			   const gp_Pnt&   P    ) 
gce_MakeCone::gce_MakeCone(const gp_Cone&   ,
			   const gp_Pnt&       ) 
{
  TheError = gce_ConfusedPoints;
}

//=========================================================================
//  Constructions d un cone parallele a un autre cone a une distance      +
//  donnee.                                                               +
//=========================================================================

//gce_MakeCone::gce_MakeCone(const gp_Cone&      cone ,
//			   const Standard_Real Dist ) 
gce_MakeCone::gce_MakeCone(const gp_Cone&       ,
			   const Standard_Real  ) 
{
  TheError = gce_Done;
}

//=========================================================================
//  Constructions d un cone de gp par son axe et deux points P1, P2.      +
//  La distance de P1 a l axe donne le rayon de la base du cone et la     +
//  distance de P2 a l axe donne le rayon du cone pour la section passant +
//  par P2.                                                               +
//=========================================================================

gce_MakeCone::gce_MakeCone(const gp_Lin&   Axis  ,
			   const gp_Pnt&   P1    ,
			   const gp_Pnt&   P2    ) 
{
  gp_Pnt P3(Axis.Location());
  gp_Pnt P4(P3.XYZ()+Axis.Direction().XYZ());
  gce_MakeCone Cone(P3,P4,P1,P2);
  if (Cone.IsDone()) {
    TheCone = Cone.Value();
    TheError = gce_Done;
  }
  else { TheError = Cone.Status(); }
}

//=========================================================================
//  cone par deux points (axe du cone.) et deux rayons (rayon des         +
//  sections passant par chacun de ces points).                           +
//=========================================================================

gce_MakeCone::gce_MakeCone(const gp_Pnt&       P1   ,
			   const gp_Pnt&       P2   ,
			   const Standard_Real R1   ,
			   const Standard_Real R2   ) 
{
  Standard_Real dist = P1.Distance(P2);
  if (dist < RealEpsilon()) { TheError = gce_NullAxis; }
  else {
    if (R1 < 0.0 || R2 < 0.0) {
      TheError = gce_NegativeRadius;
    }
    else {
      Standard_Real Angle = Abs(atan((R1-R2)/dist));
      if (Abs(PI/2.-Angle)<RealEpsilon() || Abs(Angle)<RealEpsilon()) {
	TheError = gce_NullAngle;
      }
      else {
	gp_Dir D1(P2.XYZ()-P1.XYZ());
	gp_Dir D2;
	Standard_Real x = D1.X();
	Standard_Real y = D1.Y();
	Standard_Real z = D1.Z();
	if (Abs(x) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
	else if (Abs(y) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
	else if (Abs(z) > gp::Resolution()) { D2 = gp_Dir(0.0,-z,y); }
	if (R1 > R2) { Angle *= -1; }
	TheCone = gp_Cone(gp_Ax2(P1,D1,D2),Angle,R1);
	TheError = gce_Done;
      }
    }
  }
}

const gp_Cone& gce_MakeCone::Value() const
{ 
  StdFail_NotDone_Raise_if(!TheError == gce_Done,"");
  return TheCone;
}

const gp_Cone& gce_MakeCone::Operator() const 
{
  return Value();
}

gce_MakeCone::operator gp_Cone() const
{
  return Value();
}