Constructing a straight line and a circle from an averaged scatter plot

Hello

I imported a point cloud (from a 2D scan of a surface) into SolidWorks.
I'd like to find a function or macro that allows you to construct "averaged" lines and circles from a selection of some of these points.
Currently, for example, to know the diameter of a scanned arc of a circle, I select 3 points spaced far enough apart from this arc to build a circle whose diameter I then measure. But the scanned shape is not perfect and has roughness, the diameter obtained depends quite a bit on the points selected. I would like to find a solution to create the circle by means of all the selected points (e.g. Gauss) so that there is no possible discussion about the result.

Thank you.

Hello

I offer you in attachment a macro that approximates a scatter plot, either by a straight line or by a circle, using the method of least squares.
The principles are inspired by Wikipedia articles on this subject (cf. doc attached in the zip file).
As I don't have your scanned point clouds, I had to create them in a 2D sketch by randomly scattering points, precisely in the more or less distant vicinity of a straight line or a circle...

I guess your scanned cloud should be able to be imported into a sketch. The macro will have to be adapted to this pre-existing cloud.

To be tested carefully, the behavior is not guaranteed

Good luck...


regressionnuagepts.zip
5 Likes

Thank you very much Michel for this macro (with how to use it!).  I don't know much about SW macro but I'll look at it carefully because the algorithms used/coded do the job very well.