I want to create a large set of random point cloud in 2D plane that are non-degenerate (no 3 points in a straight line in the whole set). I have a naive solution which generates a random float pair P_new(x,y) and checks with every pair of points (P1, P2) generated till now if point (P1, P2, P) lie in same line or not. This takes O(n^2) checks for each new point added to the list making the whole complexity O(n^3) which is very slow if I want to generate more than 4000 points (takes more than 40 mins).
Is there a faster way to generate these set of non-degenerate points?
I want to create a large set of random point cloud in 2D plane
Share
Instead of checking the possible points collinearity on each cycle iteration, you could compute and compare coefficients of linear equations. This coefficients should be store in container with quick search. I consider using std::set, but unordered_map could fit either and could lead to even better results.
To sum it up, I suggest the following algorithm:
p;pand existing points (I mean usualA,B&C). Here you need to doncomputations;n*log(n^2)operations at maximum.O(log(n))too.The whole complexity is reduced to
O(n^2*log(n)).This algorithm requires additional storing of
n^2*sizeof(Coefficient)memory. But this seems to be ok if you are trying to compute 4000 points only.