S
S
Sergey Sokolov2018-08-31 21:06:55
Algorithms
Sergey Sokolov, 2018-08-31 21:06:55

How to generate a random polygon without mutual intersections?

In the WxH field, I want to create an N-gon of a random shape. Without "holes", without "islands", without mutual intersections of faces.

  1. First thought: just throw random points and connect in the order of generation. There are often overlaps.
  2. Second thought: divide the field into N equal sectors from the center. Create another point in your sector. You get crooked wheels. But not a single shape, for example, a thick letter "C". And sometimes there are overlaps .
  3. Intuition tells you that you need to throw in random points, build a Delaunay triangulation , and cut out some of the faces, so as not to lose connectivity and not create islands and lakes.

Probably, in game development, this is a typical task when creating level maps. How do they create figures of a difficult random shape with the absence of holes-islands?
I would like to have a chance to appear, for example, this form:5b899a73431ab131453344.png
Useful links from @myjcom comments
  • генерация внешнего контура массива точек
  • генерация игровых ландшафтов (но с возможными дырками и островами) на Хабре и оригинал на англ.
  • список алгоритмов генерации уровней для игр, Random Walk и производные (Drunkard Walk) – интересны, но допускают дырки и острова.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel, 2018-09-02
Yazovskikh @unepic

My first thought was this:
1. Create a triangle. Add all its edges to the list.
2. Take a random edge from the list, it will be the base of the new triangle.
3. Generate a point so that a new triangle is obtained, none of whose edges intersects the edges from the list. Add two new edges to the list, remove the base.
4. Repeat from step 2 until the desired area of ​​the polygon is reached.

G
Griboks, 2018-09-02
@Griboks

1. create many simple polygons
2. mark connection points
3. constrain adjacent polygons
4. generate multiple polygons with different connections

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question