1 // Created on: 1993-03-17
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #define TOLTANGENCY 0.0000000001
25 #include <TColStd_Array1OfReal.hxx>
26 #include <math_FunctionSetRoot.hxx>
27 #include <Precision.hxx>
29 #define Debug(expr) cout<<" expr :"<<expr;
30 #define MySurf1 MyIntersectionOn2S.Function().AuxillarSurface1()
31 #define MySurf2 MyIntersectionOn2S.Function().AuxillarSurface2()
34 //--------------------------------------------------------------------------------
35 ApproxInt_PrmPrmSvSurfaces::ApproxInt_PrmPrmSvSurfaces( const ThePSurface& Surf1
36 ,const ThePSurface& Surf2):
37 MyHasBeenComputed(Standard_False),
38 MyHasBeenComputedbis(Standard_False),
39 MyIntersectionOn2S(Surf1,Surf2,TOLTANGENCY)
42 //--------------------------------------------------------------------------------
43 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::Compute( Standard_Real& u1
57 if(MyHasBeenComputed) {
58 if( (MyParOnS1.X()==u1)&&(MyParOnS1.Y()==v1)
59 &&(MyParOnS2.X()==u2)&&(MyParOnS2.Y()==v2)) {
62 else if(MyHasBeenComputedbis == Standard_False) {
67 MyParOnS1bis = MyParOnS1;
68 MyParOnS2bis = MyParOnS2;
69 MyIsTangentbis = MyIsTangent;
70 MyHasBeenComputedbis = MyHasBeenComputed;
73 if(MyHasBeenComputedbis) {
74 if( (MyParOnS1bis.X()==u1)&&(MyParOnS1bis.Y()==v1)
75 &&(MyParOnS2bis.X()==u2)&&(MyParOnS2bis.Y()==v2)) {
78 gp_Vec2d TV1(MyTguv1);
79 gp_Vec2d TV2(MyTguv2);
81 gp_Pnt2d TP1(MyParOnS1);
82 gp_Pnt2d TP2(MyParOnS2);
83 Standard_Boolean TB=MyIsTangent;
89 MyParOnS1 = MyParOnS1bis;
90 MyParOnS2 = MyParOnS2bis;
91 MyIsTangent = MyIsTangentbis;
106 MyIsTangent = Standard_True;
108 Standard_Real aParam[4];//stack vs heap allocation
109 TColStd_Array1OfReal Param (aParam[0],1,4);
110 Param(1) = u1; Param(2) = v1;
111 Param(3) = u2; Param(4) = v2;
112 math_FunctionSetRoot Rsnld(MyIntersectionOn2S.Function());
113 MyIntersectionOn2S.Perform(Param,Rsnld);
114 if (!MyIntersectionOn2S.IsDone()) {
115 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
116 return(Standard_False);
118 if (MyIntersectionOn2S.IsEmpty()) {
119 MyIsTangent=Standard_False;
120 //cout<<"\n----- Parametree Parametree : IsEmpty ds Compute "<<endl;
121 //Debug(u1); Debug(u2); Debug(v1); Debug(v2); cout<<endl;
122 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
123 return(Standard_False);
125 MyHasBeenComputed = Standard_True;
126 MyPnt = P = MyIntersectionOn2S.Point().Value();
128 MyIntersectionOn2S.Point().Parameters(u1,v1,u2,v2);
129 MyParOnS1.SetCoord(tu1,tv1);
130 MyParOnS2.SetCoord(tu2,tv2);
132 if(MyIntersectionOn2S.IsTangent()) {
133 MyIsTangent=Standard_False;
134 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
135 return(Standard_False);
137 MyTg = Tg = MyIntersectionOn2S.Direction();
138 MyTguv1 = Tguv1 = MyIntersectionOn2S.DirectionOnS1();
139 MyTguv2 = Tguv2 = MyIntersectionOn2S.DirectionOnS2();
141 //----------------------------------------------------------------------
142 //-- Si ( Tg ) TU et TV sont normes
144 //-- On a Tg = DeltaU * TU + DeltaV * TV
146 //-- soit : Tg.TU = DeltaU TU.TU + DeltaV TU.TV
147 //-- Tg.TV = DeltaU TV.TU + DeltaV TV.TV
151 //-- Tg.TU TV.TV - Tg.TV * TU.TV
152 //-- DeltaU = -------------------------------
153 //-- TU.TU TV.TV - (TU.TV)**2
155 //-- Tg.TV TU.TU - Tg.TU * TU.TV
156 //-- DeltaV = -------------------------------
157 //-- TU.TU TV.TV - (TU.TV)**2
161 Tg.Normalize(); MyTg = Tg;
163 Standard_Real DeltaU,DeltaV;
166 Standard_Real TUTV,TgTU,TgTV,TUTU,TVTV,DIS;
167 //------------------------------------------------------------
170 ThePSurfaceTool::D1(MySurf1,u1,v1,Pbid,TU,TV);
177 DIS = TUTU * TVTV - TUTV * TUTV;
178 if(fabs(DIS)<Precision::Angular()) {
179 MyIsTangent=Standard_False;
180 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
181 return(Standard_False);
184 DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ;
185 DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ;
187 Tguv1.SetCoord(DeltaU,DeltaV); MyTguv1 = Tguv1;
189 //------------------------------------------------------------
192 ThePSurfaceTool::D1(MySurf2,u2,v2,Pbid,TU,TV);
199 DIS = TUTU * TVTV - TUTV * TUTV;
200 if(fabs(DIS)<Precision::Angular()) {
201 MyIsTangent=Standard_False;
202 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
203 return(Standard_False);
206 DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ;
207 DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ;
209 Tguv2.SetCoord(DeltaU,DeltaV); MyTguv2 = Tguv2;
211 return(Standard_True);
213 //--------------------------------------------------------------------------------
214 void ApproxInt_PrmPrmSvSurfaces::Pnt(const Standard_Real u1,
215 const Standard_Real v1,
216 const Standard_Real u2,
217 const Standard_Real v2,
222 Standard_Real tu1=u1;
223 Standard_Real tu2=u2;
224 Standard_Real tv1=v1;
225 Standard_Real tv2=v2;
227 Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
229 this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
233 //--------------------------------------------------------------------------------
234 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::Tangency(const Standard_Real u1,
235 const Standard_Real v1,
236 const Standard_Real u2,
237 const Standard_Real v2,
242 Standard_Real tu1=u1;
243 Standard_Real tu2=u2;
244 Standard_Real tv1=v1;
245 Standard_Real tv2=v2;
246 Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
250 //--------------------------------------------------------------------------------
251 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::TangencyOnSurf1(const Standard_Real u1,
252 const Standard_Real v1,
253 const Standard_Real u2,
254 const Standard_Real v2,
259 Standard_Real tu1=u1;
260 Standard_Real tu2=u2;
261 Standard_Real tv1=v1;
262 Standard_Real tv2=v2;
263 Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
267 //--------------------------------------------------------------------------------
268 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::TangencyOnSurf2(const Standard_Real u1,
269 const Standard_Real v1,
270 const Standard_Real u2,
271 const Standard_Real v2,
276 Standard_Real tu1=u1;
277 Standard_Real tu2=u2;
278 Standard_Real tv1=v1;
279 Standard_Real tv2=v2;
280 Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
284 //--------------------------------------------------------------------------------
290 //------------------------------------------------------------
293 ThePSurfaceTool::D1(MySurf1,u1,v1,P,TU,TV);
298 UmTUTV2 = 1.0 - TUTV * TUTV;
300 DeltaU = (TgTU - TgTV * TUTV ) / UmTUTV2 ;
301 DeltaV = (TgTV - TgTU * TUTV ) / UmTUTV2 ;
303 Delta = 1.0 / Sqrt(DeltaU * DeltaU + DeltaV * DeltaV);
305 Tguv1.Multiplied(Delta); MyTguv1 = Tguv1;
307 //------------------------------------------------------------
310 ThePSurfaceTool::D1(MySurf2,u2,v2,P,TU,TV);
315 UmTUTV2 = 1.0 - TUTV * TUTV;
317 DeltaU = (TgTU - TgTV * TUTV ) / UmTUTV2 ;
318 DeltaV = (TgTV - TgTU * TUTV ) / UmTUTV2 ;
320 Delta = 1.0 / Sqrt(DeltaU * DeltaU + DeltaV * DeltaV);
322 Tguv2.Multiplied(Delta); MyTguv2 = Tguv2;
324 return(Standard_True);