Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

convex hull - brute force

807597Feb 22 2005 — edited Feb 28 2005
Hello!

I am implementing a brute-force algorithm for finding convex hull... If anyone knows how this is done, can you take a quick look at this? ;)
  public static void search() {
        // numbers here represent x in mark[x][0 and 1]
        // mark is the 2d-array holding all the coordinates
        int currentP1, currentP2, start;
        for (int i = 0; i < (mark.length-1 / 3); i++) {
            for (int j = 0; j < (mark.length-1 / 3); j++) {
                for (int k = 0; j < (mark.length-1 / 3); k++) {
                    if (!isLeft(mark[0], mark[i][1],
mark[j][0], mark[j][1],
mark[k][0], mark[k][1])) {
if (k == i || k == j || i == j)
break;
}
else {
// stack is a vector supposed to hold convex-points
stack.addElement(mark[i][0]);
stack.addElement(mark[i][1]);
}

}
}
}
// print out the found points
for (int i = 0; i < stack.size(); i++)
System.out.println("stack: " + stack.elementAt(i));
}
// to find out if point x,y is to the left or right of the line between x1,y1 and x2,y2
public static boolean isLeft(int x1, int y1, int x2, int y2, int x, int y) {
int result;
// ax + by + c = 0
int a = y2 - y1;
int b = x1 - x2;
int c = (x1*y2) - (y1*x2);
result = (a*x) + (b*y) - c;
if (result < 0) {
return true;
}
else
return false;
}

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 28 2005
Added on Feb 22 2005
9 comments
889 views