BHoM / BHoM_Engine

Internal manipulation of the BHoM
GNU Lesser General Public License v3.0
26 stars 13 forks source link

FitLine returns zero line for perfectly aligned points #3261

Closed pawelbaran closed 7 months ago

pawelbaran commented 7 months ago

Description:

Numerical glitch, when the input set of points in FitLine method is perfectly collinear, the method returns zero length line. Can easily be tested with points (1,0,0), (2,0,0) and (3,0,0).

peterjamesnugent commented 7 months ago

I have also had issues with this method for Points that are co-planar. I have uploaded a script here: #3261-Coplanar and Noncolinear

All cases are non colinear, and cover the following cases:

  1. Coplanar (XY Plane where Z = 0) - this produces a zero length Line;
  2. Coplanar (XY Plane where Z = 1) - this produces a Line that is vertical;
  3. Coplanar (rotated XY Plane) - this produces the correct Line;
  4. Non coplanar - this produces the correct Line.

I think the issue is that the method covers complex 3D cases (i.e. non coplanar) but is not suited to simpler cases (e.g. Cases 1-2). This is because the coefficients become zero when they are coplanar.

Perhaps we need to revisit the method used Regressions Et Trajectoires 3D or use a simpler form of regression for co-planar and colinear cases where the problem is ultimately much similar.

One discussion about 3D line fitting without matrix solving is found here (though it is iterative, so would require some balancing and testing against other methods): 3D Regression Line Fitting