Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Copyright (c) 1991-1999 Matra Datavision
0002 // Copyright (c) 1999-2022 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef _GeomConvert_FuncCylinderLSDist_HeaderFile
0016 #define _GeomConvert_FuncCylinderLSDist_HeaderFile
0017 
0018 #include <Standard.hxx>
0019 #include <Standard_DefineAlloc.hxx>
0020 
0021 #include <math_MultipleVarFunctionWithGradient.hxx>
0022 #include <TColgp_HArray1OfXYZ.hxx>
0023 #include <math_Vector.hxx>
0024 #include <gp_Dir.hxx>
0025 
0026 //! Function for search of cylinder canonic parameters: coordinates of center local coordinate system, 
0027 //! direction of axis and radius from set of points
0028 //! by least square method.
0029 //! 
0030 //! The class inherits math_MultipleVarFunctionWithGradient and thus is intended
0031 //! for use in math_BFGS algorithm.
0032 //!
0033 //! Parametrisation:
0034 //! Cylinder is defined by its axis and radius. Axis is defined by 3 cartesian coordinats it location x0, y0, z0 
0035 //! and direction, which is constant and set by user: 
0036 //! dir.x, dir.y, dir.z
0037 //! The criteria is:
0038 //! F(x0, y0, z0, theta, phi, R) = Sum[|(P(i) - Loc)^dir|^2 - R^2]^2 => min
0039 //! P(i) is i-th sample point, Loc, dir - axis location and direction, R - radius
0040 //!
0041 //! The square vector product |(P(i) - Loc)^dir|^2 is:
0042 //!
0043 //! [(y - y0)*dir.z - (z - z0)*dir.y]^2 +
0044 //! [(z - z0)*dir.x - (x - x0)*dir.z]^2 +
0045 //! [(x - x0)*dir.y - (y - y0)*dir.x]^2
0046 //!
0047 //! First derivative of square vector product are:
0048 //! Dx0 =  2*[(z - z0)*dir.x - (x - x0)*dir.z]*dir.z 
0049 //!       -2*[(x - x0)*dir.y - (y - y0)*dir.x]*dir.y
0050 //! Dy0 = -2*[(y - y0)*dir.z - (z - z0)*dir.y]*dir.z
0051 //!       +2*[(x - x0)*dir.y - (y - y0)*dir.x]*dir.x
0052 //! Dz0 =  2*[(y - y0)*dir.z - (z - z0)*dir.y]*dir.y
0053 //!       -2*[(z - z0)*dir.x - (x - x0)*dir.z]*dir.x
0054 //!
0055 //! dF/dx0 : G1(...) = 2*Sum{[...]*Dx0}
0056 //! dF/dy0 : G2(...) = 2*Sum{[...]*Dy0}
0057 //! dF/dz0 : G3(...) = 2*Sum{[...]*Dz0}
0058 //! dF/dR : G4(...) = -4*R*Sum[...]
0059 //! [...] = [|(P(i) - Loc)^dir|^2 - R^2]
0060 class GeomConvert_FuncCylinderLSDist : public math_MultipleVarFunctionWithGradient
0061 {
0062 public:
0063 
0064   DEFINE_STANDARD_ALLOC
0065 
0066   //! Constructor.
0067   Standard_EXPORT GeomConvert_FuncCylinderLSDist() {};
0068   
0069   Standard_EXPORT GeomConvert_FuncCylinderLSDist(const Handle(TColgp_HArray1OfXYZ)& thePoints,
0070                                                    const gp_Dir& theDir);
0071 
0072   void SetPoints(const Handle(TColgp_HArray1OfXYZ)& thePoints)
0073   {
0074     myPoints = thePoints;
0075   }
0076 
0077   void SetDir(const gp_Dir& theDir)
0078   {
0079     myDir = theDir;
0080   }
0081 
0082   //! Number of variables.
0083   Standard_EXPORT Standard_Integer NbVariables() const Standard_OVERRIDE;
0084 
0085   //! Value.
0086   Standard_EXPORT Standard_Boolean Value(const math_Vector& X,Standard_Real& F) Standard_OVERRIDE;
0087 
0088   //! Gradient.
0089   Standard_EXPORT Standard_Boolean Gradient(const math_Vector& X,math_Vector& G) Standard_OVERRIDE;
0090 
0091   //! Value and gradient.
0092   Standard_EXPORT Standard_Boolean Values(const math_Vector& X,Standard_Real& F,math_Vector& G) Standard_OVERRIDE;
0093 
0094 private:
0095 
0096   Handle(TColgp_HArray1OfXYZ) myPoints;
0097   gp_Dir myDir;
0098   
0099 };
0100 #endif // _GeomConvert_FuncCylinderLSDist_HeaderFile