Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:38

0001 
0002 // Copyright (c) 1991-1999 Matra Datavision
0003 // Copyright (c) 1999-2022 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _GeomConvert_FuncSphereLSDist_HeaderFile
0017 #define _GeomConvert_FuncSphereLSDist_HeaderFile
0018 
0019 #include <Standard.hxx>
0020 #include <Standard_DefineAlloc.hxx>
0021 
0022 #include <math_MultipleVarFunctionWithGradient.hxx>
0023 #include <TColgp_HArray1OfXYZ.hxx>
0024 #include <math_Vector.hxx>
0025 
0026 //! Function for search of sphere canonic parameters: coordinates of center and radius from set of moints
0027 //! by least square method.
0028 //! //!
0029 //! The class inherits math_MultipleVarFunctionWithGradient and thus is intended
0030 //! for use in math_BFGS algorithm.
0031 //!
0032 //! The criteria is:
0033 //! F(x0, y0, z0, R) = Sum[(x(i) - x0)^2 + (y(i) - y0)^2 + (z(i) - z0)^2 - R^2]^2 => min,
0034 //! x(i), y(i), z(i) - coordinates of sample points, x0, y0, z0, R - coordinates of center and radius of sphere,
0035 //! which must be defined
0036 //!
0037 //! The first derivative are:
0038 //! dF/dx0 : G1(x0, y0, z0, R) = -4*Sum{[...]*(x(i) - x0)} 
0039 //! dF/dy0 : G2(x0, y0, z0, R) = -4*Sum{[...]*(y(i) - y0)}
0040 //! dF/dz0 : G3(x0, y0, z0, R) = -4*Sum{[...]*(z(i) - z0)}
0041 //! dF/dR : G4(x0, y0, z0, R) = -4*R*Sum[...]
0042 //! [...] = [(x(i) - x0)^2 + (y(i) - y0)^2 + (z(i) - z0)^2 - R^2]
0043 //!
0044 class GeomConvert_FuncSphereLSDist : public math_MultipleVarFunctionWithGradient
0045 {
0046 public:
0047 
0048   DEFINE_STANDARD_ALLOC
0049 
0050   //! Constructor.
0051   Standard_EXPORT GeomConvert_FuncSphereLSDist() {};
0052   
0053   Standard_EXPORT GeomConvert_FuncSphereLSDist(const Handle(TColgp_HArray1OfXYZ)& thePoints);
0054 
0055   void SetPoints(const Handle(TColgp_HArray1OfXYZ)& thePoints)
0056   {
0057     myPoints = thePoints;
0058   }
0059 
0060   //! Number of variables.
0061   Standard_EXPORT Standard_Integer NbVariables() const Standard_OVERRIDE;
0062 
0063   //! Value.
0064   Standard_EXPORT Standard_Boolean Value(const math_Vector& X,Standard_Real& F) Standard_OVERRIDE;
0065 
0066   //! Gradient.
0067   Standard_EXPORT Standard_Boolean Gradient(const math_Vector& X,math_Vector& G) Standard_OVERRIDE;
0068 
0069   //! Value and gradient.
0070   Standard_EXPORT Standard_Boolean Values(const math_Vector& X,Standard_Real& F,math_Vector& G) Standard_OVERRIDE;
0071 
0072 private:
0073 
0074   Handle(TColgp_HArray1OfXYZ) myPoints;
0075   
0076 };
0077 #endif // _GeomConvert_FuncSphereLSDist_HeaderFile