I have a set of N points and I want to find the maximum number of points that lie in a single line.
I created Line2D objects with each pair of points. Obviously some of the Line2D objects will have same slope and intercept to make the points collinear. Now I want to create a kind of Hashtable to store a counter for the lines with same slope and intercept.
int x1 = 1;
int y1 = 1;
int x2 = 2;
int y2 = 2;
int x3 = 3;
int y3 = 3;
Line2D line1 = new Line2D.Double(x1, y1, x2, y2);
Line2D line2 = new Line2D.Double(x2, y2, x3, y3);
hashMap.put(line1, 1);
Obviously, if I put line2 in the hashMap, it will go to a different one. How can I do it such that since both the lines are same, the count is incremented by 1?