LeastSquaresCircle (FPScript)

21.09.2021

Calculates the least squares circle (LSCI) of a two-dimensional point set (least squares reference circle). Used to determine roundness.

Syntax

LeastSquaresCircle(Points, [ OutputOptions = LSCI_OUTPUT_MIDDLE_CIRCLE ], [ CircleSize = 5000 ] [ , Algorithm = LSCI_ALGORITHM_KASA ])
or
LeastSquaresCircle(Y, X, [ OutputOptions = LSCI_OUTPUT_MIDDLE_CIRCLE ], [ CircleSize = 5000 ] [ , Algorithm = LSCI_ALGORITHM_KASA ])

 

The syntax of the LeastSquaresCircle function consists of the following parts:

Part

Description

Points

The Y and X points for which the least squares circle is to be calculated. The same unit must be used for both components of the signal.

Permitted data structures are signal. All real data types are permitted, except calendar time und time span.

Y

The Y points used to calculate the least squares circle. If you specify a signal, then its Y component is used. The unit must match the unit of the X argument.

Permitted data structures are data series und signal. All real data types are permitted, except calendar time und time span.

X

The X points used to calculate the least squares circle. If you specify a signal, then its Y component is used. The unit must match the unit of the Y argument.

Permitted data structures are data series und signal. All real data types are permitted, except calendar time und time span.

OutputOptions

Specifies which results are to be returned. Multiple results are output as a list. If, for instance, the radius of the reference circle and the roundness should be output, the argument must contain the value LSCI_OUTPUT_MIDDLE_CIRCLE_RADIUS + LSCI_OUTPUT_ROUNDNESS.

The argument OutputOptions can have the following values:

Constant

Meaning

+ LSCI_OUTPUT_ALL

All available output.

+ LSCI_OUTPUT_CENTER_X

X coordinate of the center of the reference circle. The result is a 64-bit floating point value.

+ LSCI_OUTPUT_CENTER_Y

Y coordinate of center the reference circle. The result is a 64-bit floating point value.

+ LSCI_OUTPUT_MIDDLE_CIRCLE

The calculated reference circle (least squares reference circle). The result is a signal.

+ LSCI_OUTPUT_MIDDLE_CIRCLE_RADIUS

Radius of reference circle. The result is a 64-bit floating point value.

+ LSCI_OUTPUT_INSCRIBED_CIRCLE

The largest inscribed circle related to the reference circle. The center of the inscribed circle is equal to the center of the reference circle. The radius of the inscribed circle is the result of the minimum distance of the points to the center of the circle. The result is a signal.

+ LSCI_OUTPUT_INSCRIBED_CIRCLE_RADIUS

Radius of the inscribed circle related to the reference circle. The result is a 64-bit floating point value.

+ LSCI_OUTPUT_CIRCUMSCRIBED_CIRCLE

The smallest circumscribed circle related to the reference circle. The center of the circumscribed circle is equal to the center of the reference circle. The radius of the circumscribed circle is the result of the maximum distance of the points to the center of the circle. The result is a signal.

+ LSCI_OUTPUT_CIRCUMSCRIBED_CIRCLE_RADIUS

Radius of the circumscribed circle related to the reference circle. The result is a 64-bit floating point value.

+ LSCI_OUTPUT_ROUNDNESS

The roundness deviation. Is the difference of the radii between the circumscribed and inscribed circles. The result is a 64-bit floating point value.

+ LSCI_OUTPUT_ROUNDNESS_MAX_TO_REF

Peak-to-reference roundness deviation. The result of the difference between LSCI_OUTPUT_CIRCUMSCRIBED_CIRCLE_RADIUS and LSCI_OUTPUT_MIDDLE_CIRCLE_RADIUS. The result is a 64-bit floating point value.

+ LSCI_OUTPUT_ROUNDNESS_REF_TO_MIN

Reference-to-valley roundness deviation. The result of the difference between LSCI_OUTPUT_MIDDLE_CIRCLE_RADIUS and LSCI_OUTPUT_INSCRIBED_CIRCLE_RADIUS. The result is a 64-bit floating point value.

+ LSCI_OUTPUT_ROUNDNESS_QUADRATIC_MEAN

Root mean square of the deviations of the data points to the reference circle. Corresponds to the square root of the mean of the squares of the local roundness deviations to the least squares reference circle. The result is a 64-bit floating point value.

If this argument is omitted, it will be set to the default value LSCI_OUTPUT_MIDDLE_CIRCLE.

CircleSize

Specifies the number of values used to represent the fitted circles. If you enter zero, the original number of values are retained. The argument is considered only if one of the listed circles was selected for OutputOptions.

Permitted data structures are scalar value. All integral data types are permitted.

The value must be greater or equal to 0.

If this argument is omitted, it will be set to the default value 5000.

Algorithm

Determines the algorithm for calculating the least squares circle. The method of least squares is always used.

The argument Algorithm can have the following values:

Constant

Meaning

LSCI_ALGORITHM_KASA

To calculate the least squares LSCI circle, the following modified functional to be minimized is used: This ensures that the curve fitting can be solved explicitly with the help of a linear least squares formulation. This is known as the Kasa method; see [1], [2, Chapter 2] or [4]. The algorithm is simple, fast and robust. The algorithm gives good results when the data points are sampled along an entire circle or the majority of it (half a circle at a minimum). However, if the data points are sampled only along a small arc of the circle, the result is distorted and you often end up with circles that are too small.

LSCI_ALGORITHM_PRATT

To calculate the least squares LSCI circle, the following modified functional to be minimized is used: This is known as the Pratt method; see [3] or [4]. The algorithm is slightly slower than the Kasa method, but is accurate and still fast. Compared to the Kasa method, more precise results are achieved if the data points are within a small arc.

If this argument is omitted, it will be set to the default value LSCI_ALGORITHM_KASA.

Remarks

The values are converted to 64-bit floating points before the calculation is made.

The output options of the argument OutputOptions are visualized in the following diagram:

The results can be accessed using the following list element names:

Constant

Meaning

.["Center_X"]

X coordinate of the center of the reference circle.

.["Center_Y"]

Y coordinate of center the reference circle.

.["Middle_Circle"]

Reference circle (least squares reference circle).

.["Middle_Circle_Radius"]

Radius of reference circle.

.["Inscribed_Circle"]

The largest inscribed circle related to the reference circle.

.["Inscribed_Circle_Radius"]

Radius of the largest inscribed circle related to the reference circle.

.["Circumscribed_Circle"]

The smallest circumscribed circle related to the reference circle.

.["Circumscribed_Circle_Radius"]

Radius of the smallest circumscribed circle related to the reference circle.

.["Roundness"]

Roundness deviation as the difference between the radii of the circumscribed and inscribed circles.

.["Roundness_Max_to_Ref"]

Peak-to-reference roundness deviation.

.["Roundness_Ref_to_Min"]

Reference-to-valley roundness deviation.

.["Roundness_Quadratic_Mean"]

Root mean square of the deviations of the data points to the reference circle.

You can also always use the Formula.Listelementname syntax.

Note        The LSCI roundness calculations are based on the currently valid standard for determining roundness; see [5].

Available in

FlexPro Professional, Developer Suite

Examples

LeastSquaresCircle(y, x)

Calculates the LSCI circle (least squares reference circle) of a point set.

LeastSquaresCircle(y, x, LSCI_OUTPUT_ROUNDNESS)

Calculates the least squares circle of a point set and returns only the roundness.

LeastSquaresCircle(points, LSCI_OUTPUT_MIDDLE_CIRCLE_RADIUS + LSCI_OUTPUT_ROUNDNESS)

Calculates the least squares circle of a point set. As the result, the radius of the reference circle and the roundness are output as a list.

Dim alpha = Series(0, 2*PI, 0.05)
Dim r = 11.5 + Noise(1 # NumberOfRows(alpha), NOISE_NORMAL)
Dim points = Signal(Noise(1) + r*Sin(alpha), Noise(1) + r*Cos(alpha))
List("Points", points, "Least-Squares Circle", LeastSquaresCircle(points))

Calculates the least squares circle of randomly distributed points in the two-dimensional plane.

See Also

MaximumInscribedCircle Function

MinimumCircumscribedCircle Function

MinimumZoneCircle Function

GaussianFilter Function

NonLinCurveFit Function

Approximation Function

Circle Approximation - Analysis Object

References

[1] I. Kasa: A curve fitting procedure and its error analysis. In: IEEE Trans. Inst. Meas., Vol. 25, Pages 8-14. http://ieeexplore.ieee.org/document/6312298/,1976.

[2] L.D. Coope: Circle fitting by linear and nonlinear least squares. In: Journal of Optimization Theory and Applications, Vol. 76, Issue 2, Pages 381-388. https://link.springer.com/article/10.1007/BF00939613,1993.

[3] V. Pratt: Direct least-squares fitting of algebraic surfaces. In: Computer Graphics, Vol. 21, Pages 145-152. https://dl.acm.org/citation.cfm?id=37420,1987.

[4] A. Al-Sharadqah and N. Chernov: Error Analysis for circle fitting algorithms. In: Electron. J. Statist., Vol. 3, Pages 886-911. https://projecteuclid.org/euclid.ejs/1251119958,2009.

[5] DIN Deutsches Institut für Normung e.V.: Part 1: Vocabulary and parameters of roundness (ISO 12181-1:2011); English translation of DIN EN ISO 12181-1:2011. In: Geometrical product specifications (GPS)- Roundness. 2011.

Share article or send as email:

You might be interested in these articles