Skip to Main Content

Java Programming

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!

Random Points inside a Polygon

807589Sep 22 2008 — edited Sep 23 2008
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
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);
else
	x = x1 + (rand.nextFloat() % r);
System.out.println("x:  "+x);
if (y > y1)
	y = y1 - (rand.nextFloat() % r);
	else
	y = y1 + (rand.nextFloat() % r);
Any help will be much appreciated.
Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 21 2008
Added on Sep 22 2008
9 comments
631 views