Class GaussNewtonMinimizer
- Namespace
- CADability
- Assembly
- CADability.dll
A Gauss-Newton solver for non-linear least squares problems: given an GaussNewtonMinimizer.ErrorFunction, which computes the residuals for a set of parameters, and its GaussNewtonMinimizer.JacobiFunction, Solve(double[], int, double, double, out double, out int, out double[]) iterates from start parameters to the parameters which minimize the sum of the squared residuals. The static methods use it to fit geometric primitives to points (LineFit(IArray<GeoPoint>, double, out GeoPoint, out GeoVector), CircleFit(IArray<GeoPoint>, GeoPoint, double, double, out Ellipse), PlaneFit(IArray<GeoPoint>, double, out Plane), CylinderFit(IArray<GeoPoint>, GeoPoint, GeoVector, double, double, out CylindricalSurface), ConeFit(IArray<GeoPoint>, GeoPoint, GeoVector, double, double, out ConicalSurface), SphereFit(IArray<GeoPoint>, GeoPoint, double, double, out SphericalSurface), TorusFit(IArray<GeoPoint>, GeoPoint, GeoVector, double, double, out ToroidalSurface), QuadricFit(IArray<GeoPoint>)) and to compute extrema and intersections of curves and surfaces, e.g. when a shell is reconstructed from a triangulation. Internal numerical helper, not an entry point of the API.
public class GaussNewtonMinimizer
- Inheritance
-
GaussNewtonMinimizer
- Inherited Members
Constructors
GaussNewtonMinimizer(ErrorFunction, JacobiFunction, CheckParameterFunction, CurtailParameterFunction)
public GaussNewtonMinimizer(GaussNewtonMinimizer.ErrorFunction eFunction, GaussNewtonMinimizer.JacobiFunction jFunction, GaussNewtonMinimizer.CheckParameterFunction checkParameter = null, GaussNewtonMinimizer.CurtailParameterFunction curtailParameter = null)
Parameters
eFunctionGaussNewtonMinimizer.ErrorFunctionjFunctionGaussNewtonMinimizer.JacobiFunctioncheckParameterGaussNewtonMinimizer.CheckParameterFunctioncurtailParameterGaussNewtonMinimizer.CurtailParameterFunction
Methods
CircleFit(IArray<GeoPoint>, GeoPoint, double, double, out Ellipse)
public static double CircleFit(IArray<GeoPoint> points, GeoPoint center, double radius, double precision, out Ellipse elli)
Parameters
Returns
ConeFit(IArray<GeoPoint>, GeoPoint, GeoVector, double, double, out ConicalSurface)
public static double ConeFit(IArray<GeoPoint> points, GeoPoint apex, GeoVector axis, double theta, double precision, out ConicalSurface cs)
Parameters
pointsIArray<GeoPoint>apexGeoPointaxisGeoVectorthetadoubleprecisiondoublecsConicalSurface
Returns
ConeFitNew(IArray<GeoPoint>, GeoPoint, GeoVector, double, double, out ConicalSurface)
public static double ConeFitNew(IArray<GeoPoint> points, GeoPoint apex, GeoVector axis, double theta, double precision, out ConicalSurface cs)
Parameters
pointsIArray<GeoPoint>apexGeoPointaxisGeoVectorthetadoubleprecisiondoublecsConicalSurface
Returns
ConeFitOld(GeoPoint[], GeoPoint, GeoVector, double, out ConicalSurface)
public static double ConeFitOld(GeoPoint[] points, GeoPoint apex, GeoVector axis, double theta, out ConicalSurface cs)
Parameters
pointsGeoPoint[]apexGeoPointaxisGeoVectorthetadoublecsConicalSurface
Returns
CylinderFit(IArray<GeoPoint>, GeoPoint, GeoVector, double, double, out CylindricalSurface)
public static double CylinderFit(IArray<GeoPoint> pnts, GeoPoint center, GeoVector axis, double radius, double precision, out CylindricalSurface cs)
Parameters
pntsIArray<GeoPoint>centerGeoPointaxisGeoVectorradiusdoubleprecisiondoublecsCylindricalSurface
Returns
CylinderFitOld(IArray<GeoPoint>, GeoPoint, GeoVector, double, double, out CylindricalSurface)
public static double CylinderFitOld(IArray<GeoPoint> pnts, GeoPoint center, GeoVector axis, double radius, double precision, out CylindricalSurface cs)
Parameters
pntsIArray<GeoPoint>centerGeoPointaxisGeoVectorradiusdoubleprecisiondoublecsCylindricalSurface
Returns
Ellipse2DFit(IArray<GeoPoint2D>, GeoPoint2D, double, double, double, double, out Ellipse2D)
public static double Ellipse2DFit(IArray<GeoPoint2D> points2d, GeoPoint2D center2d, double majrad, double minrad, double angle, double precision, out Ellipse2D ellipse)
Parameters
points2dIArray<GeoPoint2D>center2dGeoPoint2DmajraddoubleminraddoubleangledoubleprecisiondoubleellipseEllipse2D
Returns
LineConnection(GeoPoint, GeoVector, GeoPoint, GeoVector, double, double, out double, out double)
p1,d1 and p2,d2 define two lines. Find a point on each line (s1,s2) so that the connection of these two points has the angle a1 to the first and a2 to the second line. a1 and a2 are provided as cosinus of the angles
public static double LineConnection(GeoPoint p1, GeoVector d1, GeoPoint p2, GeoVector d2, double a1, double a2, out double s1, out double s2)
Parameters
Returns
LineFit(IArray<GeoPoint>, double, out GeoPoint, out GeoVector)
Calculates the closest line approximating the provided points.
public static double LineFit(IArray<GeoPoint> points, double precision, out GeoPoint location, out GeoVector direction)
Parameters
pointsIArray<GeoPoint>Points to be approximated by the line
precisiondoubleRequired precision: the fit is accepted when the error of the approximation is below the square of this value, otherwise double.MaxValue is returned
locationGeoPointLocation of the line
directionGeoVectordirection of the line
Returns
- double
maximum distance to the line
PlaneFit(IArray<GeoPoint>, double, out Plane)
This is not good implemented. Do not use!
public static double PlaneFit(IArray<GeoPoint> points, double precision, out Plane plane)
Parameters
Returns
QuadricFit(IArray<GeoPoint>)
Find a quadric, which approximates the provided points. Return the maxerror of the derivation to this quadric.
public static double QuadricFit(IArray<GeoPoint> pnts)
Parameters
Returns
Solve(double[], int, double, double, out double, out int, out double[])
Solves the Gauss Newton approximation with the given startParameters and the error function and Jacobi matrix as specified in the constructor.
Returns the result in parameters and returns true, if the error function of the result is less than errorTolerance.
The iteration doesn't stop when errorTolerance is reached, but goes on until no more improvement of the result ocurres.
public bool Solve(double[] startParameters, int maxIterations, double updateLengthTolerance, double errorTolerance, out double minError, out int numIterations, out double[] parameters)
Parameters
startParametersdouble[]start parameters
maxIterationsintmaximum number of iterations
updateLengthTolerancedoublenot used
errorTolerancedoublemaximum error for positiv result
minErrordoubleeffective error
numIterationsintnumber of iterations used
parametersdouble[]resulting parameters
Returns
SphereFit(IArray<GeoPoint>, GeoPoint, double, double, out SphericalSurface)
public static double SphereFit(IArray<GeoPoint> pnts, GeoPoint center, double radius, double precision, out SphericalSurface ss)
Parameters
Returns
SphereRadiusFit(IArray<GeoPoint>, GeoPoint, double, double, out SphericalSurface)
public static double SphereRadiusFit(IArray<GeoPoint> pnts, GeoPoint center, double radius, double precision, out SphericalSurface ss)
Parameters
Returns
SurfaceCurveExtrema(ISurface, BoundingRect, ICurve, double, double, ref GeoPoint2D, ref double)
public static double SurfaceCurveExtrema(ISurface surface1, BoundingRect bounds1, ICurve curve2, double curveUmin, double curveUmax, ref GeoPoint2D uv1, ref double u2)
Parameters
surface1ISurfacebounds1BoundingRectcurve2ICurvecurveUmindoublecurveUmaxdoubleuv1GeoPoint2Du2double
Returns
SurfaceExtrema(ISurface, BoundingRect, ISurface, BoundingRect, ref GeoPoint2D, ref GeoPoint2D)
Calculates a uv points on each provided surface, so that the connection of the two points is perpendicular to the surfaces at these points. Starts a GaussNewton approximation in the center of the provided parameter bounds
public static double SurfaceExtrema(ISurface surface1, BoundingRect bounds1, ISurface surface2, BoundingRect bounds2, ref GeoPoint2D uv1, ref GeoPoint2D uv2)
Parameters
surface1ISurfacebounds1BoundingRectsurface2ISurfacebounds2BoundingRectuv1GeoPoint2Duv2GeoPoint2D
Returns
SurfaceExtrema(ISurface, BoundingRect, GeoVector, ref GeoPoint2D)
Tries to find a maximum or minimum point in the direction dir of surface within the patch bounds.
Requires the surface to implement Derivation2At(GeoPoint2D, out GeoPoint, out GeoVector, out GeoVector, out GeoVector, out GeoVector, out GeoVector).
public static double SurfaceExtrema(ISurface surface, BoundingRect bounds, GeoVector dir, ref GeoPoint2D uv)
Parameters
surfaceISurfaceThe surface
boundsBoundingRectThe patch of the surface to be examined
dirGeoVectorThe direction in which to find a minimum or maximum
uvGeoPoint2Da starting position for the search (usually the center of bounds)
Returns
- double
The error
ThreeCurveIntersection(ICurve, ICurve, ICurve, ref double, ref double, ref double)
public static double ThreeCurveIntersection(ICurve crv1, ICurve crv2, ICurve crv3, ref double u1, ref double u2, ref double u3)
Parameters
Returns
TorusFit(IArray<GeoPoint>, GeoPoint, GeoVector, double, double, out ToroidalSurface)
public static double TorusFit(IArray<GeoPoint> points, GeoPoint center, GeoVector axis, double minrad, double precision, out ToroidalSurface ts)
Parameters
pointsIArray<GeoPoint>centerGeoPointaxisGeoVectorminraddoubleprecisiondoubletsToroidalSurface