Search code examples
c++cgeometryleast-squares

Fit a circle or a spline into a bunch of 3D Points


I have some 3D Points that roughly, but clearly form a segment of a circle. I now have to determine the circle that fits best all the points. I think there has to be some sort of least squares best fit but I cant figure out how to start. The points are sorted the way they would be situated on the circle. I also have an estimated curvature at each point. I need the radius and the plane of the circle. I have to work in c/c++ or use an extern script.


Solution

  • You could use a Principal Component Analysis (PCA) to map your coordinates from three dimensions down to two dimensions.

    Compute the PCA and project your data onto the first to principal components. You can then use any 2D algorithm to find the centre of the circle and its radius. Once these have been found/fitted, you can project the centre back into 3D coordinates.

    Since your data is noisy, there will still be some data in the third dimension you squeezed out, but bear in mind that the PCA chooses this dimension such as to minimize the amount of data lost, i.e. by maximizing the amount of data that is represented in the first two components, so you should be safe.