Results 1 to 3 of 3
  1. #1
    Hayzam is offline Member
    Join Date
    May 2008
    Posts
    9
    Rep Power
    0

    Default given number of points(cordinates) , find max points lie on the same line ?

    error while given the test case , it finds 1 point while there are only 2 lines , each one has 2 points
    x [ 0 ] = 1 , y [ 0 ] = 5
    x [ 1 ] = 5 , y [ 1 ] = 1
    x [ 2 ] = 1 , y [ 2 ] = 1
    x [ 3 ] = 5 , y [ 3 ] = 5
    Java Code:
    private static void solve_it(ArrayList<point> arr) {
            System.out.println(" new test case ");
            point p = new point();
            point pp = new point();
            point ppp = new point();
            int slope, slope2, x, y, count = 0;
    
    
            int[][] index = new int[arr.size()][arr.size()];
    
            for (int i = 0; i < arr.size(); i++) {
                count = 0;
                p = arr.get(i);
                System.out.println(" x [ " + i + " ] = " + p.x + " , y [ " + i + " ] = " + p.y);
                for (int j = 0; j < arr.size(); j++) {
    
                    if (i == j) {
                        break;
                    }
                    pp = arr.get(j);
    
                    if ((pp.y - p.y) == 0) {
                        slope = 0;
                    } else {
                        slope = (pp.x - p.x) / (pp.y - p.y);
                    }
    
    
                    for (int l = 0; l < arr.size(); l++) {
                        if ((l == i) || (l == j)) {
                            break;
                        }
                        ppp = arr.get(l);
    
                        if ((ppp.y - p.y) == 0) {
                            slope2 = 0;
                        } else {
                            slope2 = (ppp.x - p.x) / (ppp.y - p.y);
                        }
                        if (slope == slope2) {
                            count++;
                        }
                    }
                    index[i][j] = count;
    
                }
    
            }
    
            for (int q = 0; q < index.length; q++) {
                System.out.println();
                for (int w = 0; w < index.length; w++) {
                    System.out.print(" " + index[q][w]);
                }
    
            }
    
            arr.clear();
    
        }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    If you are getting errors, copy and paste full text here.
    What is your algorithm?
    I see code but NO COMMENTs on how you are trying to solve the problem.

  3. #3
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Two points define a line, you may accidentally have more than two points on a line, depending on the accuracy of your measurements.

    But I don't see a question here.

Similar Threads

  1. Replies: 0
    Last Post: 06-28-2008, 09:25 PM
  2. Replies: 6
    Last Post: 06-12-2008, 09:14 AM
  3. Find nth root of a number
    By perito in forum New To Java
    Replies: 1
    Last Post: 03-03-2008, 06:51 AM
  4. how to know the number of the line
    By simon in forum New To Java
    Replies: 3
    Last Post: 08-01-2007, 04:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •