tags:

views:

740

answers:

4

I'm looking for a way to generate a set of random sided, but regular, polygons, inside a given rectangle or sector of a circle. To better explain, my given 2d space should have a random arrangement of regular polygons with various numbers of sides, so, e.g, if two hexagons are separated by a rectangle equal in length to their sides, the whole space cannot be filled with only more hexagons, some triangles may be required, etc.

I'm looking for one segment of a sort of kaleidoscope effect.

+1  A: 

I'm not sure I understand the requirements, but you can generate random regular polygons by randomly generating the following numbers:

  • radius (0 to whatever)
  • x and y of center (must be within radius of edges)
  • number of points (3 to whatever)
  • rotation (0 to 360)

To prevent overlapping, you can test each new polygon against each existing polygon and reject the new one if the distance between the centers is less than the sum of the radii.

Drawing the polygons is then a simple trig exercise.

recursive
Yeah, but the fuller the space gets, the more polygons get rejected.
Svante
That might be okay -- if a space is full enough that (say) 20 random polygons are all rejected, you might decide it's time to stop.
ShreevatsaR
A: 

You are looking for tiling algorithms. See, for example, Penrose Tiler and Tilings and Tesselations pages for a start.

PhiLho
+1  A: 

Another approach, I can think of: First decide on how many objects you want. Say 'N'

Randomly Select 3 Points in your 2D Space.

Make use of 3 points to get a virtual triangle.

Now Select another point such a way that the point is outside the virtual triangle. Now form another virtual triangle by joining this point to 2 points from previous virtual triangle and then recurisevely form "N" virtual trianlges. Incase virtual triangles crossed, then you ignore the bigger trianlge and take triangles which had formed because of crossing points as new virtualtriangles

Now Generate a INSCRIBED Circle virtually to all virtual triangles which will never be able to intersect another virtual triangle since all virtual triangles are formed by without crossing any of the triangles as expalined above.

Make use of virtual circles to form any number of regular sides by dividing 360 degress to equal slices. Now You can draw random regular polygons

lakshmanaraj
Originally I didn't want spaces between polygons, but I like this. The background could be a nice gradient or texture, or something.
ProfK
A: 

Generate N random points on a plane and extract the convex hull of the object (that is, if all polygons should be convex).

You can trivially reject before generating the convex hull if one of the points is inside another polygon. If it's not you still need to test the generated polygon against other polygons near it. (If you need to do this often, a spatial data structure is probably a something to look into).

Jasper Bekkers
No, that does NOT produce regular polygons. It is much easier to generate regular polygons, or even arbitrary convex polygons, directly, than to find convex hulls. (Not that finding convex hulls is too hard, it's just unecessary.)
ShreevatsaR