Get Random points inside custom shape

380 Views Asked by At

Im creating a game and require monsters to spawn in a specific area. I have created Nodes that connect to each other to outline where a monster can spawn. I do this by checking the maximum X axis, Y and Z of each node. However, this leaves me with a square which i dont want. how do i extrude out the shape from the square i need.

here is a picture of what i need, the values are just examples.

Area Example

Please keep in mind that the shape can have any number of nodes.

after a bit of researching, i found that convex hulls omit the the points that are on the inside. I want every point to be included in the calculated. Here you can see what a Convex Hull would do

2

There are 2 best solutions below

0
On BEST ANSWER

So i figured out my own method to do it. I basically Take two nodes at random and get the distance between them. I than get a random float between 1 and 0 that decides how far into the distance the new position should be. From this new position i take a new random node and repeat the same thing. I do this about 3 times at which point i take the last position that has been chosen.

The result is a nice even distribution of random positions all inside the custom shape which looks like this: All of the grey dots are randomly placed objects

4
On

Here is the convex hull of the red points:

enter image description here