Convex Hull

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michou
    New Member
    • May 2009
    • 3

    #1

    Convex Hull

    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?
    Last edited by Frinavale; Jun 1 '09, 07:23 PM. Reason: Moved from Introductions to Java Answers.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    What have you tried so far?
    What problems are you having running the application with eclipse?

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      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

      Comment

      • michou
        New Member
        • May 2009
        • 3

        #4
        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

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by michou
          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

          Comment

          • michou
            New Member
            • May 2009
            • 3

            #6
            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?



            Code:
            import java.awt.Graphics;
            import java.awt.Point;
            import java.awt.event.*;
            
            public class PointTool implements Tool {
            	private Point p;
            	protected JDrawFrame drawframe;
            	protected PointCanvas canvas;
            	protected int xStart;
            	protected int yStart;
            	protected Graphics onscreen;
            	protected Graphics offscreen;
            
            	public PointTool(JDrawFrame drawframe, PointCanvas canvas) {
            		super();
            		this.drawframe = drawframe;
            		this.canvas = canvas;
            	}
            
            	@Override
            	public void mousePressed(MouseEvent e) {
            		int dot = 1;
            		p = e.getPoint();
            		canvas.mouseButtonDown = true;
            		canvas.x = p.x;
            		canvas.y = p.y;
            
            		// saving the point that have been drawn
            		canvas.getJDrawFrame1().addTwoDPoint(new Vertix(canvas.x, canvas.y));
            
            		// drawing the point on the screen
            		//canvas.getOffScreenGraphics().drawOval(canvas.x, canvas.y, 10, 10);
            		canvas.getOffScreenGraphics().fillOval(canvas.x, canvas.y, 10, 10);
            		//canvas.getOffScreenGraphics().drawString(String.valueOf(dot), canvas.x,canvas.y);
            		canvas.repaint(canvas.x, canvas.y, canvas.x, canvas.y);
            		dot++;
            
            	}
            
            	@Override
            	public void mouseDragged(MouseEvent e) {
            		
            	}
            
            	@Override
            	public void mouseReleased(MouseEvent e) {
            		// handle mouse released for scribble tool
            		canvas.mouseButtonDown = false;
            
            	}
            
            }
            Last edited by JosAH; Jun 16 '09, 06:14 PM. Reason: fixed the [code] ... [/code] tags

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by michou
              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

              Comment

              Working...