1 // Created on: 1992-09-02
2 // Created by: Remi GILET
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.
17 #include <gce_MakeCone.ixx>
18 #include <StdFail_NotDone.hxx>
21 //=========================================================================
22 // Construction d un cone par son axe , le rayon de sa base et le demi +
23 // angle d ouverture. +
24 //=========================================================================
26 gce_MakeCone::gce_MakeCone(const gp_Ax2& A2 ,
27 const Standard_Real Ang ,
28 const Standard_Real Radius)
30 if (Radius < 0.0) { TheError = gce_NegativeRadius; }
32 if (Ang <= gp::Resolution() || M_PI/2-Ang <= gp::Resolution()) {
33 TheError = gce_BadAngle;
37 TheCone = gp_Cone(A2,Ang,Radius);
42 //=========================================================================
43 // Constructions d un cone de gp par quatre points P1, P2, P3 et P4. +
44 // P1 et P2 donnent l axe du cone, la distance de P3 a l axe donne +
45 // le rayon de la base du cone et la distance de P4 a l axe donne le +
46 // rayon du cone pour la section passant par P4. +
47 //=========================================================================
49 gce_MakeCone::gce_MakeCone(const gp_Pnt& P1 ,
54 if (P1.Distance(P2)<RealEpsilon() || P3.Distance(P4)<RealEpsilon()) { TheError = gce_ConfusedPoints; return; }
56 gp_Dir D1(P2.XYZ()-P1.XYZ());
57 Standard_Real cos = D1.Dot(gp_Dir(P4.XYZ()-P1.XYZ()));
58 Standard_Real dist = P1.Distance(P4);
59 gp_Pnt PP4(P1.XYZ()+cos*dist*D1.XYZ());
60 cos = D1.Dot(gp_Dir(P3.XYZ()-P1.XYZ()));
61 dist = P1.Distance(P3);
62 gp_Pnt PP3(P1.XYZ()+cos*dist*D1.XYZ());
64 Standard_Real Dist13 = PP3.Distance(P1);
65 Standard_Real Dist14 = PP4.Distance(P1);
66 if(Abs(Dist13-Dist14)<RealEpsilon()) { TheError = gce_NullAngle; return; }
68 Standard_Real Dist3 = L1.Distance(P3);
69 Standard_Real Dist4 = L1.Distance(P4);
70 Standard_Real DifRad = Dist3-Dist4;
71 Standard_Real angle = Abs(ATan(DifRad/(Dist13-Dist14)));
72 if(Abs(M_PI/2.-angle) < RealEpsilon() || Abs(angle) < RealEpsilon()) { TheError = gce_NullRadius; return; }
73 Standard_Real R1 = PP3.Distance(P3);
74 Standard_Real R2 = PP4.Distance(P4);
75 if (R1 < 0.0 || R2 < 0.0) { TheError = gce_NegativeRadius; return; }
76 gp_Dir DD1(PP4.XYZ()-PP3.XYZ());
78 Standard_Real x = DD1.X();
79 Standard_Real y = DD1.Y();
80 Standard_Real z = DD1.Z();
81 if (Abs(x) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
82 else if (Abs(y) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
83 else if (Abs(z) > gp::Resolution()) { D2 = gp_Dir(0.0,-z,y); }
84 if (R1 > R2) { angle *= -1; }
85 TheCone = gp_Cone(gp_Ax2(PP3,DD1,D2),angle,R1);
91 //=========================================================================
92 // Constructions d un cone de gp par son axe et deux points P1, P2. +
93 // La distance de P1 a l axe donne le rayon de la base du cone et la +
94 // distance de P2 a l axe donne le rayon du cone pour la section passant +
96 //=========================================================================
98 gce_MakeCone::gce_MakeCone(const gp_Ax1& Axis ,
102 gp_Pnt P3(Axis.Location());
103 gp_Pnt P4(P3.XYZ()+Axis.Direction().XYZ());
104 gce_MakeCone Cone(P3,P4,P1,P2);
106 TheCone = Cone.Value();
110 TheError = Cone.Status();
114 //=========================================================================
115 // Constructions d un cone parallele a un autre cone passant par un +
117 //=========================================================================
119 //gce_MakeCone::gce_MakeCone(const gp_Cone& cone ,
121 gce_MakeCone::gce_MakeCone(const gp_Cone& ,
124 TheError = gce_ConfusedPoints;
127 //=========================================================================
128 // Constructions d un cone parallele a un autre cone a une distance +
130 //=========================================================================
132 //gce_MakeCone::gce_MakeCone(const gp_Cone& cone ,
133 // const Standard_Real Dist )
134 gce_MakeCone::gce_MakeCone(const gp_Cone& ,
135 const Standard_Real )
140 //=========================================================================
141 // Constructions d un cone de gp par son axe et deux points P1, P2. +
142 // La distance de P1 a l axe donne le rayon de la base du cone et la +
143 // distance de P2 a l axe donne le rayon du cone pour la section passant +
145 //=========================================================================
147 gce_MakeCone::gce_MakeCone(const gp_Lin& Axis ,
151 gp_Pnt P3(Axis.Location());
152 gp_Pnt P4(P3.XYZ()+Axis.Direction().XYZ());
153 gce_MakeCone Cone(P3,P4,P1,P2);
155 TheCone = Cone.Value();
158 else { TheError = Cone.Status(); }
161 //=========================================================================
162 // cone par deux points (axe du cone.) et deux rayons (rayon des +
163 // sections passant par chacun de ces points). +
164 //=========================================================================
166 gce_MakeCone::gce_MakeCone(const gp_Pnt& P1 ,
168 const Standard_Real R1 ,
169 const Standard_Real R2 )
171 Standard_Real dist = P1.Distance(P2);
172 if (dist < RealEpsilon()) { TheError = gce_NullAxis; }
174 if (R1 < 0.0 || R2 < 0.0) {
175 TheError = gce_NegativeRadius;
178 Standard_Real Angle = Abs(atan((R1-R2)/dist));
179 if (Abs(M_PI/2.-Angle)<RealEpsilon() || Abs(Angle)<RealEpsilon()) {
180 TheError = gce_NullAngle;
183 gp_Dir D1(P2.XYZ()-P1.XYZ());
185 Standard_Real x = D1.X();
186 Standard_Real y = D1.Y();
187 Standard_Real z = D1.Z();
188 if (Abs(x) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
189 else if (Abs(y) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
190 else if (Abs(z) > gp::Resolution()) { D2 = gp_Dir(0.0,-z,y); }
191 if (R1 > R2) { Angle *= -1; }
192 TheCone = gp_Cone(gp_Ax2(P1,D1,D2),Angle,R1);
199 const gp_Cone& gce_MakeCone::Value() const
201 StdFail_NotDone_Raise_if(TheError != gce_Done,"");
205 const gp_Cone& gce_MakeCone::Operator() const
210 gce_MakeCone::operator gp_Cone() const