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 static TColStd_Array1OfReal Param(1,4);
109 Param(1) = u1; Param(2) = v1;
110 Param(3) = u2; Param(4) = v2;
111 math_FunctionSetRoot Rsnld(MyIntersectionOn2S.Function());
112 MyIntersectionOn2S.Perform(Param,Rsnld);
113 if (!MyIntersectionOn2S.IsDone()) {
114 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
115 return(Standard_False);
117 if (MyIntersectionOn2S.IsEmpty()) {
118 MyIsTangent=Standard_False;
119 //cout<<"\n----- Parametree Parametree : IsEmpty ds Compute "<<endl;
120 //Debug(u1); Debug(u2); Debug(v1); Debug(v2); cout<<endl;
121 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
122 return(Standard_False);
124 MyHasBeenComputed = Standard_True;
125 MyPnt = P = MyIntersectionOn2S.Point().Value();
127 MyIntersectionOn2S.Point().Parameters(u1,v1,u2,v2);
128 MyParOnS1.SetCoord(tu1,tv1);
129 MyParOnS2.SetCoord(tu2,tv2);
131 if(MyIntersectionOn2S.IsTangent()) {
132 MyIsTangent=Standard_False;
133 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
134 return(Standard_False);
136 MyTg = Tg = MyIntersectionOn2S.Direction();
137 MyTguv1 = Tguv1 = MyIntersectionOn2S.DirectionOnS1();
138 MyTguv2 = Tguv2 = MyIntersectionOn2S.DirectionOnS2();
140 //----------------------------------------------------------------------
141 //-- Si ( Tg ) TU et TV sont normes
143 //-- On a Tg = DeltaU * TU + DeltaV * TV
145 //-- soit : Tg.TU = DeltaU TU.TU + DeltaV TU.TV
146 //-- Tg.TV = DeltaU TV.TU + DeltaV TV.TV
150 //-- Tg.TU TV.TV - Tg.TV * TU.TV
151 //-- DeltaU = -------------------------------
152 //-- TU.TU TV.TV - (TU.TV)**2
154 //-- Tg.TV TU.TU - Tg.TU * TU.TV
155 //-- DeltaV = -------------------------------
156 //-- TU.TU TV.TV - (TU.TV)**2
160 Tg.Normalize(); MyTg = Tg;
162 Standard_Real DeltaU,DeltaV;
165 Standard_Real TUTV,TgTU,TgTV,TUTU,TVTV,DIS;
166 //------------------------------------------------------------
169 ThePSurfaceTool::D1(MySurf1,u1,v1,Pbid,TU,TV);
176 DIS = TUTU * TVTV - TUTV * TUTV;
177 if(fabs(DIS)<Precision::Angular()) {
178 MyIsTangent=Standard_False;
179 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
180 return(Standard_False);
183 DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ;
184 DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ;
186 Tguv1.SetCoord(DeltaU,DeltaV); MyTguv1 = Tguv1;
188 //------------------------------------------------------------
191 ThePSurfaceTool::D1(MySurf2,u2,v2,Pbid,TU,TV);
198 DIS = TUTU * TVTV - TUTV * TUTV;
199 if(fabs(DIS)<Precision::Angular()) {
200 MyIsTangent=Standard_False;
201 MyHasBeenComputed = MyHasBeenComputedbis = Standard_False;
202 return(Standard_False);
205 DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ;
206 DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ;
208 Tguv2.SetCoord(DeltaU,DeltaV); MyTguv2 = Tguv2;
210 return(Standard_True);
212 //--------------------------------------------------------------------------------
213 void ApproxInt_PrmPrmSvSurfaces::Pnt(const Standard_Real u1,
214 const Standard_Real v1,
215 const Standard_Real u2,
216 const Standard_Real v2,
221 Standard_Real tu1=u1;
222 Standard_Real tu2=u2;
223 Standard_Real tv1=v1;
224 Standard_Real tv2=v2;
226 Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
228 this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
232 //--------------------------------------------------------------------------------
233 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::Tangency(const Standard_Real u1,
234 const Standard_Real v1,
235 const Standard_Real u2,
236 const Standard_Real v2,
241 Standard_Real tu1=u1;
242 Standard_Real tu2=u2;
243 Standard_Real tv1=v1;
244 Standard_Real tv2=v2;
245 Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
249 //--------------------------------------------------------------------------------
250 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::TangencyOnSurf1(const Standard_Real u1,
251 const Standard_Real v1,
252 const Standard_Real u2,
253 const Standard_Real v2,
258 Standard_Real tu1=u1;
259 Standard_Real tu2=u2;
260 Standard_Real tv1=v1;
261 Standard_Real tv2=v2;
262 Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
266 //--------------------------------------------------------------------------------
267 Standard_Boolean ApproxInt_PrmPrmSvSurfaces::TangencyOnSurf2(const Standard_Real u1,
268 const Standard_Real v1,
269 const Standard_Real u2,
270 const Standard_Real v2,
275 Standard_Real tu1=u1;
276 Standard_Real tu2=u2;
277 Standard_Real tv1=v1;
278 Standard_Real tv2=v2;
279 Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2);
283 //--------------------------------------------------------------------------------
289 //------------------------------------------------------------
292 ThePSurfaceTool::D1(MySurf1,u1,v1,P,TU,TV);
297 UmTUTV2 = 1.0 - TUTV * TUTV;
299 DeltaU = (TgTU - TgTV * TUTV ) / UmTUTV2 ;
300 DeltaV = (TgTV - TgTU * TUTV ) / UmTUTV2 ;
302 Delta = 1.0 / Sqrt(DeltaU * DeltaU + DeltaV * DeltaV);
304 Tguv1.Multiplied(Delta); MyTguv1 = Tguv1;
306 //------------------------------------------------------------
309 ThePSurfaceTool::D1(MySurf2,u2,v2,P,TU,TV);
314 UmTUTV2 = 1.0 - TUTV * TUTV;
316 DeltaU = (TgTU - TgTV * TUTV ) / UmTUTV2 ;
317 DeltaV = (TgTV - TgTU * TUTV ) / UmTUTV2 ;
319 Delta = 1.0 / Sqrt(DeltaU * DeltaU + DeltaV * DeltaV);
321 Tguv2.Multiplied(Delta); MyTguv2 = Tguv2;
323 return(Standard_True);