public boolean handleEvent(Event evt) { /*this all works fine from here on*/ if (evt.id == Event.MOUSE_DOWN) { totalpoints = totalpoints + 1;/* user has added a point*/ if (totalpoints <100) /* else do nothing */ { X[totalpoints] = evt.x; Y[totalpoints] = evt.y; Graphics g = getGraphics();/* clear screen */ g.setColor(Color.white); g.fillRect(0,0,500,350); sumX = sumX + evt.x; /* recalculate mean */ sumY = sumY + evt.y; greg.x = (sumX/totalpoints); greg.y = (sumY/totalpoints); /*NEW STUFF IN HERE, WILL ATTEMPT TO GET CONVEX HULL PEELING DONE */ /* this stuff is all done whenever a new point is entered */ if (totalpoints == 5) { int i; int j; double angle; int Yminindex = 1; int Ymaxindex = 1; int Ymin = 10000; int Ymax = -1; int CH[] = new int[101]; for (i = 1; i <= 100; i++) CH[i] = 0; /* no points on CH yet */ for (i = 1; i <= totalpoints; i++) { if (Y[i] < Ymin) { Ymin = Y[i]; Yminindex = i; } else if (Y[i] == Ymin) { if (X[i] < X[Yminindex]) Yminindex = i; } if (Y[i] > Ymax) { Ymax = Y[i]; Ymaxindex = i; } else if (Y[i] == Ymax) { if (X[i] > X[Ymaxindex]) Yminindex = i; } }/* now we should have Ymin and Ymax, with indices */ double minangle = 0; double maxangle = 0; int nextCH = -1; CH[Yminindex] = 1; /* place point with smallest Ycoord on the CH */ /* the following while loop will construct the left chain of the CH, starting from Ymin and going up, (clockwise) until Ymax is reached*/ while (Yminindex != Ymaxindex) { for (i = 1; i <= totalpoints; i++) {/*consider all points */ /*if the point we're looking at is not on the CH chain yet, and it is higher than the last point added... */ if ((CH[i] == 0) && (Y[i] > Y[Yminindex])) { angle = (Y[i]-Y[Yminindex])/ (X[i]-X[Yminindex]); /*want angle to be smallest negative*/ /*if no negatives, largest positive*/ if (angle < minangle) { minangle = angle; nextCH = i; } if (minangle >= 0) if (angle > maxangle) { maxangle = angle; nextCH = i; } } } /*now we have the next CH vertex index*/ /* if there was a negative angle, it was found, otherwise the largest angle was found */ CH[nextCH] = 1; /* add point to CH */ Ymin = Y[nextCH]; /* update the new "Ymin" on the left chain*/ Yminindex = nextCH; } /*confirm algorithm on applet*/ if (totalpoints == 5) for (count = 1; count <= totalpoints; count++) if (CH[count] == 1) drawPoint((new point((X[count]+5),Y[count])), Color.green); }