# 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

As for an circle:
[lua]
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)
[/lua]

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

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

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

[editline]10:49PM[/editline]

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.

Mkay.