Fitting an ellipsoid to 3D data points

前端 未结 9 1621
终归单人心
终归单人心 2021-02-09 07:44

I have a large set of 3D data points to which I want to fit to an ellipsoid.

My maths is pretty poor, so I\'m having trouble implementing the least squares method withou

9条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-09 08:13

    Here is very simple method to find foci's, based on random search. No linear algebra used. So if you are fine with non-perfect solution:

    3DPoints - Array of some Amount of points
    vecCenter - average of 3DPoints
    AngleCosine - cos of angle between two vectors
    
    RandomOrder(3DPoints)
    
    vecFocus := (0, 0, 0)
    for i := 0 to Amount:
        vecRadius := 3DPoints[i] - vecCenter
    
        // Change vecRadius direction to parallel
        if AngleCosine(vecFocus, vecRadius) < 0 then
            vecRadius *= -1
        vecFocus += (vecRadius - vecFocus) / Amount
    

    Result can be improved by passing array 2nd time in backward direction Foci's placed at vecCenter +/- vecFocus

提交回复
热议问题