1 // Created on: 1993-03-17
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1993-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
9 // under the terms of the GNU Lesser General Public 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 #define TOLTANGENCY 0.0000000001
20 #include <TColStd_Array1OfReal.hxx>
21 #include <math_FunctionSetRoot.hxx>
22 #include <Precision.hxx>
24 #define Debug(expr) cout<<" expr :"<<expr;
25 #define MySurf1 MyIntersectionOn2S.Function().AuxillarSurface1()
26 #define MySurf2 MyIntersectionOn2S.Function().AuxillarSurface2()
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)
37 //--------------------------------------------------------------------------------
38 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::Compute( Standard_Real& u1
52 if(MyHasBeenComputed) {
53 if( (MyParOnS1.X()==u1)&&(MyParOnS1.Y()==v1)
54 &&(MyParOnS2.X()==u2)&&(MyParOnS2.Y()==v2)) {
57 else if(MyHasBeenComputedbis == Standard_False) {
62 MyParOnS1bis = MyParOnS1;
63 MyParOnS2bis = MyParOnS2;
64 MyIsTangentbis = MyIsTangent;
65 MyHasBeenComputedbis = MyHasBeenComputed;
68 if(MyHasBeenComputedbis) {
69 if( (MyParOnS1bis.X()==u1)&&(MyParOnS1bis.Y()==v1)
70 &&(MyParOnS2bis.X()==u2)&&(MyParOnS2bis.Y()==v2)) {
73 gp_Vec2d TV1(MyTguv1);
74 gp_Vec2d TV2(MyTguv2);
76 gp_Pnt2d TP1(MyParOnS1);
77 gp_Pnt2d TP2(MyParOnS2);
78 Standard_Boolean TB=MyIsTangent;
84 MyParOnS1 = MyParOnS1bis;
85 MyParOnS2 = MyParOnS2bis;
86 MyIsTangent = MyIsTangentbis;
101 MyIsTangent = Standard_True;
103 Standard_Real aParam[4];//stack vs heap allocation
104 TColStd_Array1OfReal Param (aParam[0],1,4);
105 Param(1) = u1; Param(2) = v1;
106 Param(3) = u2; Param(4) = v2;
107 math_FunctionSetRoot Rsnld(MyIntersectionOn2S.Function());
108 MyIntersectionOn2S.Perform(Param,Rsnld);
109 if (!MyIntersectionOn2S.IsDone()) {
110 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
111 return(Standard_False);
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);
120 MyHasBeenComputed = Standard_True;
121 MyPnt = P = MyIntersectionOn2S.Point().Value();
123 MyIntersectionOn2S.Point().Parameters(u1,v1,u2,v2);
124 MyParOnS1.SetCoord(tu1,tv1);
125 MyParOnS2.SetCoord(tu2,tv2);
127 if(MyIntersectionOn2S.IsTangent()) {
128 MyIsTangent=Standard_False;
129 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
130 return(Standard_False);
132 MyTg = Tg = MyIntersectionOn2S.Direction();
133 MyTguv1 = Tguv1 = MyIntersectionOn2S.DirectionOnS1();
134 MyTguv2 = Tguv2 = MyIntersectionOn2S.DirectionOnS2();
136 //----------------------------------------------------------------------
137 //-- Si ( Tg ) TU et TV sont normes
139 //-- On a Tg = DeltaU * TU + DeltaV * TV
141 //-- soit : Tg.TU = DeltaU TU.TU + DeltaV TU.TV
142 //-- Tg.TV = DeltaU TV.TU + DeltaV TV.TV
146 //-- Tg.TU TV.TV - Tg.TV * TU.TV
147 //-- DeltaU = -------------------------------
148 //-- TU.TU TV.TV - (TU.TV)**2
150 //-- Tg.TV TU.TU - Tg.TU * TU.TV
151 //-- DeltaV = -------------------------------
152 //-- TU.TU TV.TV - (TU.TV)**2
156 Tg.Normalize(); MyTg = Tg;
158 Standard_Real DeltaU,DeltaV;
161 Standard_Real TUTV,TgTU,TgTV,TUTU,TVTV,DIS;
162 //------------------------------------------------------------
165 ThePSurfaceTool::D1(MySurf1,u1,v1,Pbid,TU,TV);
172 DIS = TUTU * TVTV - TUTV * TUTV;
173 if(fabs(DIS)<Precision::Angular()) {
174 MyIsTangent=Standard_False;
175 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
176 return(Standard_False);
179 DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ;
180 DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ;
182 Tguv1.SetCoord(DeltaU,DeltaV); MyTguv1 = Tguv1;
184 //------------------------------------------------------------
187 ThePSurfaceTool::D1(MySurf2,u2,v2,Pbid,TU,TV);
194 DIS = TUTU * TVTV - TUTV * TUTV;
195 if(fabs(DIS)<Precision::Angular()) {
196 MyIsTangent=Standard_False;
197 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
198 return(Standard_False);
201 DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ;
202 DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ;
204 Tguv2.SetCoord(DeltaU,DeltaV); MyTguv2 = Tguv2;
206 return(Standard_True);
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,
217 Standard_Real tu1=u1;
218 Standard_Real tu2=u2;
219 Standard_Real tv1=v1;
220 Standard_Real tv2=v2;
221 this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
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,
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);
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,
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);
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,
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);
275 //--------------------------------------------------------------------------------
281 //------------------------------------------------------------
284 ThePSurfaceTool::D1(MySurf1,u1,v1,P,TU,TV);
289 UmTUTV2 = 1.0 - TUTV * TUTV;
291 DeltaU = (TgTU - TgTV * TUTV ) / UmTUTV2 ;
292 DeltaV = (TgTV - TgTU * TUTV ) / UmTUTV2 ;
294 Delta = 1.0 / Sqrt(DeltaU * DeltaU + DeltaV * DeltaV);
296 Tguv1.Multiplied(Delta); MyTguv1 = Tguv1;
298 //------------------------------------------------------------
301 ThePSurfaceTool::D1(MySurf2,u2,v2,P,TU,TV);
306 UmTUTV2 = 1.0 - TUTV * TUTV;
308 DeltaU = (TgTU - TgTV * TUTV ) / UmTUTV2 ;
309 DeltaV = (TgTV - TgTU * TUTV ) / UmTUTV2 ;
311 Delta = 1.0 / Sqrt(DeltaU * DeltaU + DeltaV * DeltaV);
313 Tguv2.Multiplied(Delta); MyTguv2 = Tguv2;
315 return(Standard_True);