Results 1 to 2 of 2
  1. #1
    nidhirastogi is offline Member
    Join Date
    Jul 2008
    Rep Power

    Default Random Points inside a Polygon

    Hi all
    I need to create 3 random points inside a hexagon whose median I have.
    I used the following logic, but all I am getting is points on the median and not around it within the boundary.
    Can someone please help me correct my logic.

    Description of variables:
    x1 and y1 are the median of the hexagon.
    r is the radius of the hexagon

    Java Code:
    int x1 = vnuBS.returnBSList().get(i).getMedianPoint().x;
    int y1 = vnuBS.returnBSList().get(i).getMedianPoint().y;
    double x = x1 + r * Math.cos(generator.irand(0,360));
    double y = y1 + r * Math.sin(generator.irand(0,360));
    if (x > x1)
    	x = x1 - (rand.nextFloat() % r);
    	x = x1 + (rand.nextFloat() % r);
    System.out.println("x:  "+x);
    if (y > y1)
    	y = y1 - (rand.nextFloat() % r);
    	y = y1 + (rand.nextFloat() % r);
    Any help will be much appreciated.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    On vacation
    Rep Power


    I've been away from academic math for a while.
    What are the various variables used for? why are x,y double vs int
    Can you explain the logic of your code?

Similar Threads

  1. Replies: 8
    Last Post: 04-19-2009, 05:50 PM
  2. Replies: 2
    Last Post: 08-24-2008, 12:30 AM
  3. How to Fill a Polygon in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:10 PM
  4. How to Draw a Polygon in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:09 PM
  5. random numbers without random class`
    By carlos123 in forum New To Java
    Replies: 4
    Last Post: 01-17-2008, 11:44 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