Table of Contents

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

eFunction GaussNewtonMinimizer.ErrorFunction
jFunction GaussNewtonMinimizer.JacobiFunction
checkParameter GaussNewtonMinimizer.CheckParameterFunction
curtailParameter GaussNewtonMinimizer.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

points IArray<GeoPoint>
center GeoPoint
radius double
precision double
elli Ellipse

Returns

double

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

points IArray<GeoPoint>
apex GeoPoint
axis GeoVector
theta double
precision double
cs ConicalSurface

Returns

double

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

points IArray<GeoPoint>
apex GeoPoint
axis GeoVector
theta double
precision double
cs ConicalSurface

Returns

double

ConeFitOld(GeoPoint[], GeoPoint, GeoVector, double, out ConicalSurface)

public static double ConeFitOld(GeoPoint[] points, GeoPoint apex, GeoVector axis, double theta, out ConicalSurface cs)

Parameters

points GeoPoint[]
apex GeoPoint
axis GeoVector
theta double
cs ConicalSurface

Returns

double

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

pnts IArray<GeoPoint>
center GeoPoint
axis GeoVector
radius double
precision double
cs CylindricalSurface

Returns

double

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

pnts IArray<GeoPoint>
center GeoPoint
axis GeoVector
radius double
precision double
cs CylindricalSurface

Returns

double

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

points2d IArray<GeoPoint2D>
center2d GeoPoint2D
majrad double
minrad double
angle double
precision double
ellipse Ellipse2D

Returns

double

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

p1 GeoPoint
d1 GeoVector
p2 GeoPoint
d2 GeoVector
a1 double
a2 double
s1 double
s2 double

Returns

double

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

points IArray<GeoPoint>

Points to be approximated by the line

precision double

Required precision: the fit is accepted when the error of the approximation is below the square of this value, otherwise double.MaxValue is returned

location GeoPoint

Location of the line

direction GeoVector

direction 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

points IArray<GeoPoint>
precision double
plane Plane

Returns

double

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

pnts IArray<GeoPoint>

Returns

double

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

startParameters double[]

start parameters

maxIterations int

maximum number of iterations

updateLengthTolerance double

not used

errorTolerance double

maximum error for positiv result

minError double

effective error

numIterations int

number of iterations used

parameters double[]

resulting parameters

Returns

bool

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

pnts IArray<GeoPoint>
center GeoPoint
radius double
precision double
ss SphericalSurface

Returns

double

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

pnts IArray<GeoPoint>
center GeoPoint
radius double
precision double
ss SphericalSurface

Returns

double

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

surface1 ISurface
bounds1 BoundingRect
curve2 ICurve
curveUmin double
curveUmax double
uv1 GeoPoint2D
u2 double

Returns

double

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

surface1 ISurface
bounds1 BoundingRect
surface2 ISurface
bounds2 BoundingRect
uv1 GeoPoint2D
uv2 GeoPoint2D

Returns

double

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

surface ISurface

The surface

bounds BoundingRect

The patch of the surface to be examined

dir GeoVector

The direction in which to find a minimum or maximum

uv GeoPoint2D

a 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

crv1 ICurve
crv2 ICurve
crv3 ICurve
u1 double
u2 double
u3 double

Returns

double

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

points IArray<GeoPoint>
center GeoPoint
axis GeoVector
minrad double
precision double
ts ToroidalSurface

Returns

double