random position inside of any shape

How can i get a random position inside of any posible shape? Be that shape a square, a circle, a tetrahedron, an octogon, or what ever. How can i get as random vector position inside of it? Thanks guys :slight_smile:

As for an circle:
local num = math.random(0,360)
local x = math.cos(num) * size
local y = math.sin(num) * size
local z = 1337
local pos = Vector(x,y, z)

As for an square:
local x = math.random(-size,size)
local y = math.random(-size,size)
local z = 1337
local pos = Vector(x,y, z)

The rest i dont know :0

No, i mean, independent of the shape, is it possible to get a random position inside of it?

You can’t get a random position inside a shape independent of the shape AFAIK, you need a separate algorithm for each shape.

Aww ok thanks. So if i have the shape, there is no way of dynamicly generating an algorithm to get a random placement inside of it?

I’m not sure, not easily anyway.

Damn. Thanks :slight_smile:

This is easy to do as long as the shape is made out of triangles, and all it’s corners are convex.


Actually, I think it’s easy to do without convex corners too:3:

Do it :shobon:

First I want to know that this is what he actually wants.

Okay. What i want to do, is spawn props randomly inside of a defined space. This space will probably be cylindrical(spelling?) but in effect, i want it to be any possible shape.

I’m offering to write a function that returns a random position from within a mesh given, however generating the shapes you will have to do yourself:wink:

Okay. I can do that. Cool. Thanks dude.

I’m gonna be away for a few days, don’t expect anything before next weekend.