1 // Created on: 1995-07-18
2 // Created by: Modelistation
3 // Copyright (c) 1995-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 under
9 // the terms of the GNU Lesser General Public License 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.
18 #include <Extrema_FuncPSNorm.hxx>
19 #include <Adaptor3d_Surface.hxx>
20 #include <Extrema_POnSurf.hxx>
21 #include <GeomAbs_IsoType.hxx>
24 #include <math_Matrix.hxx>
25 #include <Precision.hxx>
26 #include <Standard_TypeMismatch.hxx>
28 Extrema_FuncPSNorm::Extrema_FuncPSNorm ()
30 myPinit = Standard_False;
31 mySinit = Standard_False;
34 //=============================================================================
35 Extrema_FuncPSNorm::Extrema_FuncPSNorm (const gp_Pnt& P,
36 const Adaptor3d_Surface& S)
39 myS = (Adaptor3d_SurfacePtr)&S;
40 myPinit = Standard_True;
41 mySinit = Standard_True;
44 //=============================================================================
45 void Extrema_FuncPSNorm::Initialize(const Adaptor3d_Surface& S)
47 myS = (Adaptor3d_SurfacePtr)&S;
48 mySinit = Standard_True;
53 //=============================================================================
55 void Extrema_FuncPSNorm::SetPoint(const gp_Pnt& P)
58 myPinit = Standard_True;
63 //=============================================================================
65 //=============================================================================
67 Standard_Integer Extrema_FuncPSNorm::NbVariables () const { return 2;}
68 //=============================================================================
70 Standard_Integer Extrema_FuncPSNorm::NbEquations () const { return 2;}
71 //=============================================================================
73 Standard_Boolean Extrema_FuncPSNorm::Value (const math_Vector& UV,
76 if (!myPinit || !mySinit) throw Standard_TypeMismatch();
80 myS->D1(myU,myV,myPs,Dus,Dvs);
82 gp_Vec PPs (myP,myPs);
89 //=============================================================================
91 Standard_Boolean Extrema_FuncPSNorm::Derivatives (const math_Vector& UV,
95 return Values(UV,F,Df);
97 //=============================================================================
99 Standard_Boolean Extrema_FuncPSNorm::Values (const math_Vector& UV,
103 if (!myPinit || !mySinit) throw Standard_TypeMismatch();
106 gp_Vec Dus, Dvs, Duus, Dvvs, Duvs;
107 myS->D2(myU,myV,myPs,Dus,Dvs,Duus,Dvvs,Duvs);
109 gp_Vec PPs (myP,myPs);
111 Df(1,1) = Dus.SquareMagnitude() + PPs.Dot(Duus);
112 Df(1,2) = Dvs.Dot(Dus) + PPs.Dot(Duvs);
114 Df(2,2) = Dvs.SquareMagnitude() + PPs.Dot(Dvvs);
120 return Standard_True;
122 //=============================================================================
124 Standard_Integer Extrema_FuncPSNorm::GetStateNumber ()
126 if (!myPinit || !mySinit) throw Standard_TypeMismatch();
127 //comparison of solution with previous solutions
128 Standard_Integer i = 1, nbSol = mySqDist.Length();
129 Standard_Real tol2d = Precision::PConfusion() * Precision::PConfusion();
131 for( ; i <= nbSol; i++)
133 Standard_Real aU, aV;
134 myPoint(i).Parameter(aU, aV);
135 if( ((myU - aU ) * (myU - aU ) + (myV - aV ) * (myV - aV )) <= tol2d )
140 mySqDist.Append(myPs.SquareDistance(myP));
141 myPoint.Append(Extrema_POnSurf(myU,myV,myPs));
144 //=============================================================================
146 Standard_Integer Extrema_FuncPSNorm::NbExt () const
148 return mySqDist.Length();
150 //=============================================================================
152 Standard_Real Extrema_FuncPSNorm::SquareDistance (const Standard_Integer N) const
154 if (!myPinit || !mySinit) throw Standard_TypeMismatch();
155 return mySqDist.Value(N);
157 //=============================================================================
159 const Extrema_POnSurf& Extrema_FuncPSNorm::Point (const Standard_Integer N) const
161 if (!myPinit || !mySinit) throw Standard_TypeMismatch();
162 return myPoint.Value(N);