public void CollinearTest() { { Point3 p1 = new Point3(0, 0, 0); Point3 p2 = new Point3(0, 0, 1); Point3 p3 = new Point3(0, 0, 2); bool expected = true; bool actual = Point3.Collinear(p1, p2, p3); Assert.AreEqual(expected, actual); } { Point3 p1 = new Point3(1, 0, 0); Point3 p2 = new Point3(0, 2, 1); Point3 p3 = new Point3(0, 0, 2); bool expected = false; bool actual = Point3.Collinear(p1, p2, p3); Assert.AreEqual(expected, actual); } { Point3 p1 = new Point3(134, 268, 402); Point3 p2 = new Point3(329, 658, 98); Point3 p3 = new Point3(125, 250, 375); bool expected = false; bool actual = Point3.Collinear(p1, p2, p3); Assert.AreEqual(expected, actual); } }
private bool degenerate(int[] indices) { Point3 p1 = points[indices[0]]; Point3 p2 = points[indices[1]]; Point3 p3 = points[indices[2]]; return(Point3.Collinear(p1, p2, p3)); }
private void computeInliers() { int[] bestInliers = null; int maxInliers = 0; int size = this.points.Length; Plane plane = null; int count = 0; // Total number of trials performed double N = maxEvaluations; // Estimative of number of trials needed. // While the number of trials is less than our estimative, // and we have not surpassed the maximum number of trials while (count < N) { int[] sample = null; int samplings = 0; // While the number of samples attempted is less // than the maximum limit of attempts while (samplings < maxSamplings) { // Select at random s data points to form a trial model. sample = Accord.Statistics.Tools.RandomSample(size, 3); if (!Point3.Collinear(points[sample[0]], points[sample[1]], points[sample[2]])) { Point3[] randPoints = { points[sample[0]], points[sample[1]], points[sample[2]] }; // Fit model using the random selection of points plane = fitting(randPoints); break; } samplings++; // Increase the samplings counter } if (plane == null) { throw new ConvergenceException("A model could not be inferred from the data points"); } // Now, evaluate the distances between total points and the model returning the // indices of the points that are inliers (according to a distance threshold t). inliers = distance(plane, this.threshold); // Check if the model was the model which highest number of inliers: if (bestInliers == null || inliers.Length > maxInliers) { // Yes, this model has the highest number of inliers. maxInliers = inliers.Length; // Set the new maximum, bestPlane = plane; // This is the best model found so far, bestInliers = inliers; // Store the indices of the current inliers. // Update estimate of N, the number of trials to ensure we pick, // with probability p, a data set with no outliers. double pInlier = (double)inliers.Length / (double)size; double pNoOutliers = 1.0 - System.Math.Pow(pInlier, 3); N = System.Math.Ceiling(System.Math.Log(1.0 - 0.99) / System.Math.Log(pNoOutliers)); } Console.WriteLine("trail " + count + " out of " + N); count++; // Increase the trial counter. if (count > maxEvaluations) { int[] temp = { }; inliers = temp; return; } } inliers = bestInliers; }