• random position inside of any shape
    14 replies, posted
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:
[QUOTE=ralle105;21125566]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:[/QUOTE] Do it :shobon:
[QUOTE=bromvlieg;21126367]Do it :shobon:[/QUOTE] 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.
[QUOTE=bobthe2lol;21127465]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.[/QUOTE] 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.
Sorry, you need to Log In to post a reply to this thread.