Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1993-03-17 |
2 | // Created by: Laurent BUCHARD | |
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 | |
17 | #define TOLTANGENCY 0.0000000001 | |
18 | ||
19 | ||
20 | #include <TColStd_Array1OfReal.hxx> | |
21 | #include <math_FunctionSetRoot.hxx> | |
416594fe | 22 | #include <Precision.hxx> |
7fd59977 | 23 | |
24 | #define Debug(expr) cout<<" expr :"<<expr; | |
25 | #define MySurf1 MyIntersectionOn2S.Function().AuxillarSurface1() | |
26 | #define MySurf2 MyIntersectionOn2S.Function().AuxillarSurface2() | |
27 | ||
28 | ||
29 | //-------------------------------------------------------------------------------- | |
30 | ApproxInt_PrmPrmSvSurfaces::ApproxInt_PrmPrmSvSurfaces( const ThePSurface& Surf1 | |
31 | ,const ThePSurface& Surf2): | |
32 | MyHasBeenComputed(Standard_False), | |
33 | MyHasBeenComputedbis(Standard_False), | |
34 | MyIntersectionOn2S(Surf1,Surf2,TOLTANGENCY) | |
35 | { | |
36 | } | |
37 | //-------------------------------------------------------------------------------- | |
38 | Standard_Boolean ApproxInt_PrmPrmSvSurfaces::Compute( Standard_Real& u1 | |
39 | ,Standard_Real& v1 | |
40 | ,Standard_Real& u2 | |
41 | ,Standard_Real& v2 | |
42 | ,gp_Pnt& P | |
43 | ,gp_Vec& Tg | |
44 | ,gp_Vec2d& Tguv1 | |
45 | ,gp_Vec2d& Tguv2) { | |
46 | ||
47 | Standard_Real tu1=u1; | |
48 | Standard_Real tu2=u2; | |
49 | Standard_Real tv1=v1; | |
50 | Standard_Real tv2=v2; | |
51 | ||
52 | if(MyHasBeenComputed) { | |
53 | if( (MyParOnS1.X()==u1)&&(MyParOnS1.Y()==v1) | |
54 | &&(MyParOnS2.X()==u2)&&(MyParOnS2.Y()==v2)) { | |
55 | return(MyIsTangent); | |
56 | } | |
57 | else if(MyHasBeenComputedbis == Standard_False) { | |
58 | MyTgbis = MyTg; | |
59 | MyTguv1bis = MyTguv1; | |
60 | MyTguv2bis = MyTguv2; | |
61 | MyPntbis = MyPnt; | |
62 | MyParOnS1bis = MyParOnS1; | |
63 | MyParOnS2bis = MyParOnS2; | |
64 | MyIsTangentbis = MyIsTangent; | |
65 | MyHasBeenComputedbis = MyHasBeenComputed; | |
66 | } | |
67 | } | |
68 | if(MyHasBeenComputedbis) { | |
69 | if( (MyParOnS1bis.X()==u1)&&(MyParOnS1bis.Y()==v1) | |
70 | &&(MyParOnS2bis.X()==u2)&&(MyParOnS2bis.Y()==v2)) { | |
71 | ||
72 | gp_Vec TV(MyTg); | |
73 | gp_Vec2d TV1(MyTguv1); | |
74 | gp_Vec2d TV2(MyTguv2); | |
75 | gp_Pnt TP(MyPnt); | |
76 | gp_Pnt2d TP1(MyParOnS1); | |
77 | gp_Pnt2d TP2(MyParOnS2); | |
78 | Standard_Boolean TB=MyIsTangent; | |
79 | ||
80 | MyTg = MyTgbis; | |
81 | MyTguv1 = MyTguv1bis; | |
82 | MyTguv2 = MyTguv2bis; | |
83 | MyPnt = MyPntbis; | |
84 | MyParOnS1 = MyParOnS1bis; | |
85 | MyParOnS2 = MyParOnS2bis; | |
86 | MyIsTangent = MyIsTangentbis; | |
87 | ||
88 | MyTgbis = TV; | |
89 | MyTguv1bis = TV1; | |
90 | MyTguv2bis = TV2; | |
91 | MyPntbis = TP; | |
92 | MyParOnS1bis = TP1; | |
93 | MyParOnS2bis = TP2; | |
94 | MyIsTangentbis = TB; | |
95 | ||
96 | return(MyIsTangent); | |
97 | } | |
98 | } | |
99 | ||
100 | ||
101 | MyIsTangent = Standard_True; | |
102 | ||
1ef32e96 RL |
103 | Standard_Real aParam[4];//stack vs heap allocation |
104 | TColStd_Array1OfReal Param (aParam[0],1,4); | |
7fd59977 | 105 | Param(1) = u1; Param(2) = v1; |
106 | Param(3) = u2; Param(4) = v2; | |
107 | math_FunctionSetRoot Rsnld(MyIntersectionOn2S.Function()); | |
7fd59977 | 108 | MyIntersectionOn2S.Perform(Param,Rsnld); |
7fd59977 | 109 | if (!MyIntersectionOn2S.IsDone()) { |
110 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
111 | return(Standard_False); | |
112 | } | |
113 | if (MyIntersectionOn2S.IsEmpty()) { | |
114 | MyIsTangent=Standard_False; | |
115 | //cout<<"\n----- Parametree Parametree : IsEmpty ds Compute "<<endl; | |
116 | //Debug(u1); Debug(u2); Debug(v1); Debug(v2); cout<<endl; | |
117 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
118 | return(Standard_False); | |
119 | } | |
120 | MyHasBeenComputed = Standard_True; | |
121 | MyPnt = P = MyIntersectionOn2S.Point().Value(); | |
122 | ||
123 | MyIntersectionOn2S.Point().Parameters(u1,v1,u2,v2); | |
124 | MyParOnS1.SetCoord(tu1,tv1); | |
125 | MyParOnS2.SetCoord(tu2,tv2); | |
126 | ||
127 | if(MyIntersectionOn2S.IsTangent()) { | |
128 | MyIsTangent=Standard_False; | |
129 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
130 | return(Standard_False); | |
131 | } | |
132 | MyTg = Tg = MyIntersectionOn2S.Direction(); | |
133 | MyTguv1 = Tguv1 = MyIntersectionOn2S.DirectionOnS1(); | |
134 | MyTguv2 = Tguv2 = MyIntersectionOn2S.DirectionOnS2(); | |
135 | ||
136 | //---------------------------------------------------------------------- | |
137 | //-- Si ( Tg ) TU et TV sont normes | |
138 | //-- | |
139 | //-- On a Tg = DeltaU * TU + DeltaV * TV | |
140 | //-- | |
141 | //-- soit : Tg.TU = DeltaU TU.TU + DeltaV TU.TV | |
142 | //-- Tg.TV = DeltaU TV.TU + DeltaV TV.TV | |
143 | //-- | |
144 | //-- Donc : | |
145 | //-- | |
146 | //-- Tg.TU TV.TV - Tg.TV * TU.TV | |
147 | //-- DeltaU = ------------------------------- | |
148 | //-- TU.TU TV.TV - (TU.TV)**2 | |
149 | //-- | |
150 | //-- Tg.TV TU.TU - Tg.TU * TU.TV | |
151 | //-- DeltaV = ------------------------------- | |
152 | //-- TU.TU TV.TV - (TU.TV)**2 | |
153 | //-- | |
154 | //-- | |
155 | ||
156 | Tg.Normalize(); MyTg = Tg; | |
157 | ||
158 | Standard_Real DeltaU,DeltaV; | |
159 | gp_Vec TU,TV; | |
160 | gp_Pnt Pbid; | |
161 | Standard_Real TUTV,TgTU,TgTV,TUTU,TVTV,DIS; | |
162 | //------------------------------------------------------------ | |
163 | //-- Calcul de Tguv1 | |
164 | //-- | |
165 | ThePSurfaceTool::D1(MySurf1,u1,v1,Pbid,TU,TV); | |
166 | ||
167 | TUTU = TU.Dot(TU); | |
168 | TVTV = TV.Dot(TV); | |
169 | TUTV = TU.Dot(TV); | |
170 | TgTU = Tg.Dot(TU); | |
171 | TgTV = Tg.Dot(TV); | |
172 | DIS = TUTU * TVTV - TUTV * TUTV; | |
416594fe | 173 | if(fabs(DIS)<Precision::Angular()) { |
174 | MyIsTangent=Standard_False; | |
175 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
176 | return(Standard_False); | |
177 | } | |
7fd59977 | 178 | |
179 | DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ; | |
180 | DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ; | |
181 | ||
182 | Tguv1.SetCoord(DeltaU,DeltaV); MyTguv1 = Tguv1; | |
183 | ||
184 | //------------------------------------------------------------ | |
185 | //-- Calcul de Tguv2 | |
186 | //-- | |
187 | ThePSurfaceTool::D1(MySurf2,u2,v2,Pbid,TU,TV); | |
188 | ||
189 | TUTU = TU.Dot(TU); | |
190 | TVTV = TV.Dot(TV); | |
191 | TUTV = TU.Dot(TV); | |
192 | TgTU = Tg.Dot(TU); | |
193 | TgTV = Tg.Dot(TV); | |
194 | DIS = TUTU * TVTV - TUTV * TUTV; | |
416594fe | 195 | if(fabs(DIS)<Precision::Angular()) { |
196 | MyIsTangent=Standard_False; | |
197 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
198 | return(Standard_False); | |
199 | } | |
7fd59977 | 200 | |
201 | DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ; | |
202 | DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ; | |
203 | ||
204 | Tguv2.SetCoord(DeltaU,DeltaV); MyTguv2 = Tguv2; | |
205 | ||
206 | return(Standard_True); | |
207 | } | |
208 | //-------------------------------------------------------------------------------- | |
209 | void ApproxInt_PrmPrmSvSurfaces::Pnt(const Standard_Real u1, | |
210 | const Standard_Real v1, | |
211 | const Standard_Real u2, | |
212 | const Standard_Real v2, | |
213 | gp_Pnt& P) { | |
214 | gp_Pnt aP; | |
215 | gp_Vec aT; | |
216 | gp_Vec2d aTS1,aTS2; | |
217 | Standard_Real tu1=u1; | |
218 | Standard_Real tu2=u2; | |
219 | Standard_Real tv1=v1; | |
220 | Standard_Real tv2=v2; | |
7fd59977 | 221 | this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2); |
7fd59977 | 222 | P=MyPnt; |
223 | } | |
224 | //-------------------------------------------------------------------------------- | |
225 | Standard_Boolean ApproxInt_PrmPrmSvSurfaces::Tangency(const Standard_Real u1, | |
226 | const Standard_Real v1, | |
227 | const Standard_Real u2, | |
228 | const Standard_Real v2, | |
229 | gp_Vec& T) { | |
230 | gp_Pnt aP; | |
231 | gp_Vec aT; | |
232 | gp_Vec2d aTS1,aTS2; | |
233 | Standard_Real tu1=u1; | |
234 | Standard_Real tu2=u2; | |
235 | Standard_Real tv1=v1; | |
236 | Standard_Real tv2=v2; | |
237 | Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2); | |
238 | T=MyTg; | |
239 | return(t); | |
240 | } | |
241 | //-------------------------------------------------------------------------------- | |
242 | Standard_Boolean ApproxInt_PrmPrmSvSurfaces::TangencyOnSurf1(const Standard_Real u1, | |
243 | const Standard_Real v1, | |
244 | const Standard_Real u2, | |
245 | const Standard_Real v2, | |
246 | gp_Vec2d& T) { | |
247 | gp_Pnt aP; | |
248 | gp_Vec aT; | |
249 | gp_Vec2d aTS1,aTS2; | |
250 | Standard_Real tu1=u1; | |
251 | Standard_Real tu2=u2; | |
252 | Standard_Real tv1=v1; | |
253 | Standard_Real tv2=v2; | |
254 | Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2); | |
255 | T=MyTguv1; | |
256 | return(t); | |
257 | } | |
258 | //-------------------------------------------------------------------------------- | |
259 | Standard_Boolean ApproxInt_PrmPrmSvSurfaces::TangencyOnSurf2(const Standard_Real u1, | |
260 | const Standard_Real v1, | |
261 | const Standard_Real u2, | |
262 | const Standard_Real v2, | |
263 | gp_Vec2d& T) { | |
264 | gp_Pnt aP; | |
265 | gp_Vec aT; | |
266 | gp_Vec2d aTS1,aTS2; | |
267 | Standard_Real tu1=u1; | |
268 | Standard_Real tu2=u2; | |
269 | Standard_Real tv1=v1; | |
270 | Standard_Real tv2=v2; | |
271 | Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2); | |
272 | T=MyTguv2; | |
273 | return(t); | |
274 | } | |
275 | //-------------------------------------------------------------------------------- | |
276 | ||
277 | ||
278 | ||
279 | ||
280 | #if 0 | |
281 | //------------------------------------------------------------ | |
282 | //-- Calcul de Tguv1 | |
283 | //-- | |
284 | ThePSurfaceTool::D1(MySurf1,u1,v1,P,TU,TV); | |
285 | ||
286 | TUTV = TU.Dot(TV); | |
287 | TgTU = Tg.Dot(TU); | |
288 | TgTV = Tg.Dot(TV); | |
289 | UmTUTV2 = 1.0 - TUTV * TUTV; | |
290 | ||
291 | DeltaU = (TgTU - TgTV * TUTV ) / UmTUTV2 ; | |
292 | DeltaV = (TgTV - TgTU * TUTV ) / UmTUTV2 ; | |
293 | ||
294 | Delta = 1.0 / Sqrt(DeltaU * DeltaU + DeltaV * DeltaV); | |
295 | ||
296 | Tguv1.Multiplied(Delta); MyTguv1 = Tguv1; | |
297 | ||
298 | //------------------------------------------------------------ | |
299 | //-- Calcul de Tguv2 | |
300 | //-- | |
301 | ThePSurfaceTool::D1(MySurf2,u2,v2,P,TU,TV); | |
302 | ||
303 | TUTV = TU.Dot(TV); | |
304 | TgTU = Tg.Dot(TU); | |
305 | TgTV = Tg.Dot(TV); | |
306 | UmTUTV2 = 1.0 - TUTV * TUTV; | |
307 | ||
308 | DeltaU = (TgTU - TgTV * TUTV ) / UmTUTV2 ; | |
309 | DeltaV = (TgTV - TgTU * TUTV ) / UmTUTV2 ; | |
310 | ||
311 | Delta = 1.0 / Sqrt(DeltaU * DeltaU + DeltaV * DeltaV); | |
312 | ||
313 | Tguv2.Multiplied(Delta); MyTguv2 = Tguv2; | |
314 | ||
315 | return(Standard_True); | |
316 | } | |
317 | #endif | |
318 | ||
319 | ||
320 | ||
321 |