Skip to content

Commit

Permalink
#3285 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelbaran committed Feb 15, 2024
1 parent 59dea19 commit 578a48e
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions Geometry_Engine/Query/IsCollinear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,14 @@ public static bool IsCollinear(this List<Point> pts, double tolerance = Toleranc
if (pts.Count < 3)
return true;

double[,] vMatrix = new double[pts.Count - 1, 3];
for (int i = 0; i < pts.Count - 1; i++)
{
vMatrix[i, 0] = pts[i + 1].X - pts[0].X;
vMatrix[i, 1] = pts[i + 1].Y - pts[0].Y;
vMatrix[i, 2] = pts[i + 1].Z - pts[0].Z;
}

double REFTolerance = vMatrix.REFTolerance(tolerance);
double[,] rref = vMatrix.RowEchelonForm(true, REFTolerance);
int nonZeroRows = rref.CountNonZeroRows(REFTolerance);
return nonZeroRows < 2;
Line fitLine = pts.FitLine(tolerance);

// Coincident points can be considered collinear
if (fitLine == null)
return true;

double sqTol = tolerance * tolerance;
return pts.All(x => x.SquareDistance(fitLine, true) < sqTol);
}


Expand Down

0 comments on commit 578a48e

Please sign in to comment.