Connecting Tech Pros Worldwide Forums | Help | Site Map

Convex Hull

Newbie
 
Join Date: May 2009
Posts: 3
#1: May 29 '09
hello,
I'm new in using java. i'm trying to use eclipse to be able to run a convex hull problem which means you are given a number of points in a plane then you connect points so that the points are enclosed in a convex.

can someone help how i can do it using eclipse?

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#2: Jun 1 '09

re: Convex Hull


What have you tried so far?
What problems are you having running the application with eclipse?
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#3: Jun 1 '09

re: Convex Hull


Your problem isn't really a convex hull problem but a problem of "how to do this bloody thing in Eclipse"? Right? A 2D convex hull problem is like wrapping a rubber band around a bunch of points/nails and see how it wraps around them.

please elaborate on your problem.

kind regards,

Jos
Newbie
 
Join Date: May 2009
Posts: 3
#4: Jun 15 '09

re: Convex Hull


ohhh thank you for your replies.
let me try to change my problem and be more specific.
i'm a beginner in java, i want to write codes that will allow me to enter points in a plane then by clicking on a button i want to find the minimum circle that encloses all the points entered in the plane.
can someone help me please?
thank you
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#5: Jun 15 '09

re: Convex Hull


Quote:

Originally Posted by michou View Post

ohhh thank you for your replies.
let me try to change my problem and be more specific.
i'm a beginner in java, i want to write codes that will allow me to enter points in a plane then by clicking on a button i want to find the minimum circle that encloses all the points entered in the plane.
can someone help me please?
thank you

That circle won't be the convex hull of the set of points; you want to find the largest distance d == |P_i, P_j| for any point P_i and P_j. That distance d is the diameter of the circle you're looking for and points P_i and P_j are on opposite sides of that circle.

kind regards,

Jos
Newbie
 
Join Date: May 2009
Posts: 3
#6: Jun 16 '09

re: Convex Hull


hello,
thank you for your reply, up to now i have wrote some codes that can allow me to enter points in a plane but im still comfused about how i can write codes to find the maximum distance between two points (the two points have to be in different sides) then that maximum distance has to be the diameter of the circle that must enclose all the points entered.
the above is the program that i wrote so far but i need to include a function that calculate the maximum distance then use that maximum distance to draw a circle:
can u help?



Expand|Select|Wrap|Line Numbers
  1. import java.awt.Graphics;
  2. import java.awt.Point;
  3. import java.awt.event.*;
  4.  
  5. public class PointTool implements Tool {
  6.     private Point p;
  7.     protected JDrawFrame drawframe;
  8.     protected PointCanvas canvas;
  9.     protected int xStart;
  10.     protected int yStart;
  11.     protected Graphics onscreen;
  12.     protected Graphics offscreen;
  13.  
  14.     public PointTool(JDrawFrame drawframe, PointCanvas canvas) {
  15.         super();
  16.         this.drawframe = drawframe;
  17.         this.canvas = canvas;
  18.     }
  19.  
  20.     @Override
  21.     public void mousePressed(MouseEvent e) {
  22.         int dot = 1;
  23.         p = e.getPoint();
  24.         canvas.mouseButtonDown = true;
  25.         canvas.x = p.x;
  26.         canvas.y = p.y;
  27.  
  28.         // saving the point that have been drawn
  29.         canvas.getJDrawFrame1().addTwoDPoint(new Vertix(canvas.x, canvas.y));
  30.  
  31.         // drawing the point on the screen
  32.         //canvas.getOffScreenGraphics().drawOval(canvas.x, canvas.y, 10, 10);
  33.         canvas.getOffScreenGraphics().fillOval(canvas.x, canvas.y, 10, 10);
  34.         //canvas.getOffScreenGraphics().drawString(String.valueOf(dot), canvas.x,canvas.y);
  35.         canvas.repaint(canvas.x, canvas.y, canvas.x, canvas.y);
  36.         dot++;
  37.  
  38.     }
  39.  
  40.     @Override
  41.     public void mouseDragged(MouseEvent e) {
  42.  
  43.     }
  44.  
  45.     @Override
  46.     public void mouseReleased(MouseEvent e) {
  47.         // handle mouse released for scribble tool
  48.         canvas.mouseButtonDown = false;
  49.  
  50.     }
  51.  
  52. }
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#7: Jun 16 '09

re: Convex Hull


Quote:

Originally Posted by michou View Post

hello,
thank you for your reply, up to now i have wrote some codes that can allow me to enter points in a plane but im still comfused about how i can write codes to find the maximum distance between two points (the two points have to be in different sides) then that maximum distance has to be the diameter of the circle that must enclose all the points entered.
the above is the program that i wrote so far but i need to include a function that calculate the maximum distance then use that maximum distance to draw a circle:
can u help?

What do you mean by "different sides"? Different sides of what? In order to find a maximum distance between two points you have to use two loops: one for every point P_i and one loop for every point P_j; find the distance between point P_i and P_j and remember the index values of i and j.

kind regards,

Jos
Reply