ScriptSpot

Forum topic · General Scripting

Volume

By br0t · 2011-08-31

Description

Hey,
I would like to randomly distribute objects in a spherical volume defined by a radius, how would I do that?
Cheers

Comments (2)

Hi Br0t

Anubis · 2011-08-31

I think you need random radius and angle rotation.
Pseudo code (not tetsed):

thePivot = [0,0,150]
theRadius = 300

for i = 1 to 100 do (
	r = random 0 theRadius
	p = Point pos:[0,0,r]
	about thePivot (
		rotate p (random -90 90) x_azis
		rotate p (random -90 90) y_azis
		rotate p (random -90 90) z_azis
	)
)

Let me know is this helps at all ;)

Hmm... or maybe the next is better?...

thePivot = [0,0,150]
theRadius = 300
p = undefined

for i = 1 to 100 do (
	r = random 0 theRadius
	in coordsys thePivot (p = Point pos:[0,0,r])
	about thePivot (
		rotate p (random -90 90) x_azis
		rotate p (random -90 90) y_azis
		rotate p (random -90 90) z_azis
	)
)

miauu · 2011-08-31

You can check RTTAssist sours code. I'v developed the explode function that explode objects in a spherical volume, but not randomly. May be you can modify the code to fit your needs. :)