7fd59977 |
1 | // File: gce_MakeCirc.cxx |
2 | // Created: Wed Sep 2 10:34:28 1992 |
3 | // Author: Remi GILET |
4 | // <reg@sdsun1> |
5 | |
6 | #include <gce_MakeCone.ixx> |
7 | #include <StdFail_NotDone.hxx> |
8 | #include <gp.hxx> |
9 | |
10 | //========================================================================= |
11 | // Construction d un cone par son axe , le rayon de sa base et le demi + |
12 | // angle d ouverture. + |
13 | //========================================================================= |
14 | |
15 | gce_MakeCone::gce_MakeCone(const gp_Ax2& A2 , |
16 | const Standard_Real Ang , |
17 | const Standard_Real Radius) |
18 | { |
19 | if (Radius < 0.0) { TheError = gce_NegativeRadius; } |
20 | else { |
c6541a0c |
21 | if (Ang <= gp::Resolution() || M_PI/2-Ang <= gp::Resolution()) { |
7fd59977 |
22 | TheError = gce_BadAngle; |
23 | } |
24 | else { |
25 | TheError = gce_Done; |
26 | TheCone = gp_Cone(A2,Ang,Radius); |
27 | } |
28 | } |
29 | } |
30 | |
31 | //========================================================================= |
32 | // Constructions d un cone de gp par quatre points P1, P2, P3 et P4. + |
33 | // P1 et P2 donnent l axe du cone, la distance de P3 a l axe donne + |
34 | // le rayon de la base du cone et la distance de P4 a l axe donne le + |
35 | // rayon du cone pour la section passant par P4. + |
36 | //========================================================================= |
37 | |
38 | gce_MakeCone::gce_MakeCone(const gp_Pnt& P1 , |
39 | const gp_Pnt& P2 , |
40 | const gp_Pnt& P3 , |
41 | const gp_Pnt& P4 ) |
42 | { |
43 | if (P1.Distance(P2)<RealEpsilon() || P3.Distance(P4)<RealEpsilon()) { TheError = gce_ConfusedPoints; return; } |
44 | |
45 | gp_Dir D1(P2.XYZ()-P1.XYZ()); |
46 | Standard_Real cos = D1.Dot(gp_Dir(P4.XYZ()-P1.XYZ())); |
47 | Standard_Real dist = P1.Distance(P4); |
48 | gp_Pnt PP4(P1.XYZ()+cos*dist*D1.XYZ()); |
49 | cos = D1.Dot(gp_Dir(P3.XYZ()-P1.XYZ())); |
50 | dist = P1.Distance(P3); |
51 | gp_Pnt PP3(P1.XYZ()+cos*dist*D1.XYZ()); |
52 | |
53 | Standard_Real Dist13 = PP3.Distance(P1); |
54 | Standard_Real Dist14 = PP4.Distance(P1); |
55 | if(Abs(Dist13-Dist14)<RealEpsilon()) { TheError = gce_NullAngle; return; } |
56 | gp_Lin L1(P1,D1); |
57 | Standard_Real Dist3 = L1.Distance(P3); |
58 | Standard_Real Dist4 = L1.Distance(P4); |
59 | Standard_Real DifRad = Dist3-Dist4; |
60 | Standard_Real angle = Abs(ATan(DifRad/(Dist13-Dist14))); |
c6541a0c |
61 | if(Abs(M_PI/2.-angle) < RealEpsilon() || Abs(angle) < RealEpsilon()) { TheError = gce_NullRadius; return; } |
7fd59977 |
62 | Standard_Real R1 = PP3.Distance(P3); |
63 | Standard_Real R2 = PP4.Distance(P4); |
64 | if (R1 < 0.0 || R2 < 0.0) { TheError = gce_NegativeRadius; return; } |
65 | gp_Dir DD1(PP4.XYZ()-PP3.XYZ()); |
66 | gp_Dir D2; |
67 | Standard_Real x = DD1.X(); |
68 | Standard_Real y = DD1.Y(); |
69 | Standard_Real z = DD1.Z(); |
70 | if (Abs(x) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); } |
71 | else if (Abs(y) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); } |
72 | else if (Abs(z) > gp::Resolution()) { D2 = gp_Dir(0.0,-z,y); } |
73 | if (R1 > R2) { angle *= -1; } |
74 | TheCone = gp_Cone(gp_Ax2(PP3,DD1,D2),angle,R1); |
75 | TheError = gce_Done; |
76 | } |
77 | |
78 | |
79 | |
80 | //========================================================================= |
81 | // Constructions d un cone de gp par son axe et deux points P1, P2. + |
82 | // La distance de P1 a l axe donne le rayon de la base du cone et la + |
83 | // distance de P2 a l axe donne le rayon du cone pour la section passant + |
84 | // par P2. + |
85 | //========================================================================= |
86 | |
87 | gce_MakeCone::gce_MakeCone(const gp_Ax1& Axis , |
88 | const gp_Pnt& P1 , |
89 | const gp_Pnt& P2 ) |
90 | { |
91 | gp_Pnt P3(Axis.Location()); |
92 | gp_Pnt P4(P3.XYZ()+Axis.Direction().XYZ()); |
93 | gce_MakeCone Cone(P3,P4,P1,P2); |
94 | if (Cone.IsDone()) { |
95 | TheCone = Cone.Value(); |
96 | TheError = gce_Done; |
97 | } |
98 | else { |
99 | TheError = Cone.Status(); |
100 | } |
101 | } |
102 | |
103 | //========================================================================= |
104 | // Constructions d un cone parallele a un autre cone passant par un + |
105 | // donne. + |
106 | //========================================================================= |
107 | |
108 | //gce_MakeCone::gce_MakeCone(const gp_Cone& cone , |
109 | // const gp_Pnt& P ) |
110 | gce_MakeCone::gce_MakeCone(const gp_Cone& , |
111 | const gp_Pnt& ) |
112 | { |
113 | TheError = gce_ConfusedPoints; |
114 | } |
115 | |
116 | //========================================================================= |
117 | // Constructions d un cone parallele a un autre cone a une distance + |
118 | // donnee. + |
119 | //========================================================================= |
120 | |
121 | //gce_MakeCone::gce_MakeCone(const gp_Cone& cone , |
122 | // const Standard_Real Dist ) |
123 | gce_MakeCone::gce_MakeCone(const gp_Cone& , |
124 | const Standard_Real ) |
125 | { |
126 | TheError = gce_Done; |
127 | } |
128 | |
129 | //========================================================================= |
130 | // Constructions d un cone de gp par son axe et deux points P1, P2. + |
131 | // La distance de P1 a l axe donne le rayon de la base du cone et la + |
132 | // distance de P2 a l axe donne le rayon du cone pour la section passant + |
133 | // par P2. + |
134 | //========================================================================= |
135 | |
136 | gce_MakeCone::gce_MakeCone(const gp_Lin& Axis , |
137 | const gp_Pnt& P1 , |
138 | const gp_Pnt& P2 ) |
139 | { |
140 | gp_Pnt P3(Axis.Location()); |
141 | gp_Pnt P4(P3.XYZ()+Axis.Direction().XYZ()); |
142 | gce_MakeCone Cone(P3,P4,P1,P2); |
143 | if (Cone.IsDone()) { |
144 | TheCone = Cone.Value(); |
145 | TheError = gce_Done; |
146 | } |
147 | else { TheError = Cone.Status(); } |
148 | } |
149 | |
150 | //========================================================================= |
151 | // cone par deux points (axe du cone.) et deux rayons (rayon des + |
152 | // sections passant par chacun de ces points). + |
153 | //========================================================================= |
154 | |
155 | gce_MakeCone::gce_MakeCone(const gp_Pnt& P1 , |
156 | const gp_Pnt& P2 , |
157 | const Standard_Real R1 , |
158 | const Standard_Real R2 ) |
159 | { |
160 | Standard_Real dist = P1.Distance(P2); |
161 | if (dist < RealEpsilon()) { TheError = gce_NullAxis; } |
162 | else { |
163 | if (R1 < 0.0 || R2 < 0.0) { |
164 | TheError = gce_NegativeRadius; |
165 | } |
166 | else { |
167 | Standard_Real Angle = Abs(atan((R1-R2)/dist)); |
c6541a0c |
168 | if (Abs(M_PI/2.-Angle)<RealEpsilon() || Abs(Angle)<RealEpsilon()) { |
7fd59977 |
169 | TheError = gce_NullAngle; |
170 | } |
171 | else { |
172 | gp_Dir D1(P2.XYZ()-P1.XYZ()); |
173 | gp_Dir D2; |
174 | Standard_Real x = D1.X(); |
175 | Standard_Real y = D1.Y(); |
176 | Standard_Real z = D1.Z(); |
177 | if (Abs(x) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); } |
178 | else if (Abs(y) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); } |
179 | else if (Abs(z) > gp::Resolution()) { D2 = gp_Dir(0.0,-z,y); } |
180 | if (R1 > R2) { Angle *= -1; } |
181 | TheCone = gp_Cone(gp_Ax2(P1,D1,D2),Angle,R1); |
182 | TheError = gce_Done; |
183 | } |
184 | } |
185 | } |
186 | } |
187 | |
188 | const gp_Cone& gce_MakeCone::Value() const |
189 | { |
190 | StdFail_NotDone_Raise_if(!TheError == gce_Done,""); |
191 | return TheCone; |
192 | } |
193 | |
194 | const gp_Cone& gce_MakeCone::Operator() const |
195 | { |
196 | return Value(); |
197 | } |
198 | |
199 | gce_MakeCone::operator gp_Cone() const |
200 | { |
201 | return Value(); |
202 | } |
203 | |