b311480e |
1 | // Created on: 1993-08-24 |
2 | // Created by: Bruno DUMORTIER |
3 | // Copyright (c) 1993-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 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <ElSLib.hxx> |
7fd59977 |
19 | #include <gp.hxx> |
42cf5bc1 |
20 | #include <gp_Circ.hxx> |
21 | #include <gp_Cone.hxx> |
22 | #include <gp_Elips.hxx> |
23 | #include <gp_Hypr.hxx> |
24 | #include <gp_Lin.hxx> |
25 | #include <gp_Parab.hxx> |
7fd59977 |
26 | #include <gp_Trsf.hxx> |
42cf5bc1 |
27 | #include <gp_Vec.hxx> |
7fd59977 |
28 | #include <gp_Vec2d.hxx> |
42cf5bc1 |
29 | #include <Precision.hxx> |
30 | #include <ProjLib_Cone.hxx> |
31 | #include <Standard_NoSuchObject.hxx> |
7fd59977 |
32 | |
33 | //======================================================================= |
34 | //function : ProjLib_Cone |
35 | //purpose : |
36 | //======================================================================= |
7fd59977 |
37 | ProjLib_Cone::ProjLib_Cone() |
38 | { |
39 | } |
40 | |
41 | |
42 | //======================================================================= |
43 | //function : ProjLib_Cone |
44 | //purpose : |
45 | //======================================================================= |
46 | |
47 | ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co) |
48 | { |
49 | Init(Co); |
50 | } |
51 | |
52 | |
53 | //======================================================================= |
54 | //function : ProjLib_Cone |
55 | //purpose : |
56 | //======================================================================= |
57 | |
58 | ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co, const gp_Lin& L) |
59 | { |
60 | Init(Co); |
61 | Project(L); |
62 | } |
63 | |
64 | |
65 | //======================================================================= |
66 | //function : ProjLib_Cone |
67 | //purpose : |
68 | //======================================================================= |
69 | |
70 | ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co, const gp_Circ& C) |
71 | { |
72 | Init(Co); |
73 | Project(C); |
74 | } |
75 | |
76 | |
77 | //======================================================================= |
78 | //function : Init |
79 | //purpose : |
80 | //======================================================================= |
81 | |
82 | void ProjLib_Cone::Init(const gp_Cone& Co) |
83 | { |
84 | myType = GeomAbs_OtherCurve; |
85 | myCone = Co; |
86 | myIsPeriodic = Standard_False; |
87 | isDone = Standard_False; |
88 | } |
89 | |
7fd59977 |
90 | //======================================================================= |
91 | //function : Project |
92 | //purpose : |
93 | //======================================================================= |
94 | |
95 | void ProjLib_Cone::Project(const gp_Lin& L) |
96 | { |
b0700466 |
97 | gp_Pnt aPnt = L.Location(), anApex = myCone.Apex(); |
98 | |
99 | Standard_Real aDeltaV = 0.0; |
7fd59977 |
100 | |
101 | Standard_Real U,V; |
b0700466 |
102 | if (aPnt.IsEqual(anApex, Precision::Confusion())) |
103 | { |
104 | //Take another point in the line L, which does not coincide with the cone apex. |
105 | aPnt.Translate(L.Direction().XYZ()); |
106 | aDeltaV = 1.0; // == ||L.Direction()|| == 1.0 |
107 | } |
8f8398f6 |
108 | |
b0700466 |
109 | ElSLib::ConeParameters(myCone.Position(), myCone.RefRadius(), myCone.SemiAngle(), aPnt, |
8f8398f6 |
110 | U, V); |
111 | // |
7fd59977 |
112 | gp_Pnt P; |
113 | gp_Vec Vu, Vv; |
114 | |
8f8398f6 |
115 | ElSLib::ConeD1(U, V, myCone.Position(), myCone.RefRadius(), myCone.SemiAngle(), |
7fd59977 |
116 | P, Vu, Vv); |
117 | |
8f8398f6 |
118 | gp_Dir Dv(Vv); |
b0700466 |
119 | if(Dv.IsParallel(L.Direction(), Precision::Angular())) |
120 | { |
121 | // L is parallel to U-isoline of the cone. |
7fd59977 |
122 | myType = GeomAbs_Line; |
7fd59977 |
123 | |
b0700466 |
124 | const Standard_Real aSign = Sign(1.0, L.Direction().Dot(Dv)); |
125 | gp_Pnt2d P2d(U, V - aDeltaV*aSign); |
126 | gp_Dir2d D2d(0., aSign); |
7fd59977 |
127 | |
128 | myLin = gp_Lin2d( P2d, D2d); |
129 | |
130 | isDone = Standard_True; |
b0700466 |
131 | } |
7fd59977 |
132 | } |
133 | |
134 | |
135 | //======================================================================= |
136 | //function : Project |
137 | //purpose : |
138 | //======================================================================= |
139 | |
140 | void ProjLib_Cone::Project(const gp_Circ& C) |
141 | { |
142 | myType = GeomAbs_Line; |
143 | |
144 | gp_Ax3 ConePos = myCone.Position(); |
145 | gp_Ax3 CircPos = C.Position(); |
32e849eb |
146 | // |
147 | if (!ConePos.Direction().IsParallel(CircPos.Direction(), Precision::Angular())) { |
148 | isDone = Standard_False; |
149 | return; |
150 | } |
151 | // |
7fd59977 |
152 | gp_Dir ZCone = ConePos.XDirection().Crossed(ConePos.YDirection()); |
153 | gp_Dir ZCir = CircPos.XDirection().Crossed(CircPos.YDirection()); |
154 | |
155 | Standard_Real U, V; |
156 | Standard_Real x = ConePos.XDirection().Dot(CircPos.XDirection()); |
157 | Standard_Real y = ConePos.YDirection().Dot(CircPos.XDirection()); |
158 | Standard_Real z |
159 | = gp_Vec(myCone.Location(),C.Location()).Dot(ConePos.Direction()); |
160 | |
161 | // pour trouver le point U V, on reprend le code de ElSLib |
162 | // sans appliquer la Trsf au point ( aller retour inutile). |
163 | if ( x == 0.0 && y == 0.0 ) { |
164 | U = 0.; |
165 | } |
166 | else if ( -myCone.RefRadius() > z * Tan(myCone.SemiAngle())) { |
167 | U = ATan2(-y, -x); |
168 | } |
169 | else { |
170 | U = ATan2( y, x); |
171 | } |
c6541a0c |
172 | if ( U < 0.) U += 2*M_PI; |
7fd59977 |
173 | |
174 | V = z / Cos(myCone.SemiAngle()); |
175 | |
176 | gp_Pnt2d P2d1 (U, V); |
177 | gp_Dir2d D2d; |
178 | if ( ZCone.Dot(ZCir) > 0.) |
179 | D2d.SetCoord(1., 0.); |
180 | else |
181 | D2d.SetCoord(-1., 0.); |
182 | |
183 | myLin = gp_Lin2d(P2d1, D2d); |
184 | isDone = Standard_True; |
185 | } |
186 | |
187 | void ProjLib_Cone::Project(const gp_Elips& E) |
188 | { |
189 | ProjLib_Projector::Project(E); |
190 | } |
191 | |
192 | void ProjLib_Cone::Project(const gp_Parab& P) |
193 | { |
194 | ProjLib_Projector::Project(P); |
195 | } |
196 | |
197 | void ProjLib_Cone::Project(const gp_Hypr& H) |
198 | { |
199 | ProjLib_Projector::Project(H); |
200 | } |
201 | |