Placing objects at a radius

Blitz3D Forums/Blitz3D Programming/Placing objects at a radius

slenkar(Posted 2005) [#1]
How do I place objects at random places AT a certain radius.
E.g. places on a sphere

OR

How would I place objects at random places on a polygon?


RiverRatt(Posted 2005) [#2]
entitypivot()


Ross C(Posted 2005) [#3]
Create your entity at the centre point, rotate it a random amount, then moveentity the distance you want :o)


slenkar(Posted 2005) [#4]
there is no such command,
if you mean entityparent, the objects have to be placed first

(at random places -but as long as they are the same distance from the centre)

If you mean createpivot-same as above

I need the equation -not a command

-Ross C yep thats good, thanks


Matty(Posted 2005) [#5]
A very simple method would be to do this:

Angle1=Rand(0,360)
Angle2=Rand(0,360)
Angle3=Rand(0,360)

X=CentreOfSphereX+Radius*Cos(Angle1)
Y=CentreOfSphereY+Radius*Sin(Angle2)
Z=CentreofSphereZ+Radius*Sin(Angle3)

positionentity myentity,X,Y,Z




Floyd(Posted 2005) [#6]
The problem with 'random Rotation' is that points will be much more densely packed at the poles than at the equator.

For example, the polar cap with pitch values in the range 88 to 90
will get about as many points as the equatorial band with pitch -1 to +1.
But the equatorial band has about 57 times as much surface area.

The easiest way to generate random points on a sphere is to generate points inside, then scale up.
Repeat
	
	x# = Rnd(-1,1)
	y# = Rnd(-1,1)
	z# = Rnd(-1,1)   ; (x,y,z) is random point in cube
	
	s# = x*x + y*y + z*z
	
Until s <= 1.0 And s > 0.0   ; reject points outside sphere, or at center.

; (x,y,z) is now a randomly chosen point in the unit sphere.

s = Sqr(s)
x = x/s  ; note that we already made sure s is nonzero.
y = y/s
z = z/s

; (x,y,z) is now a randomly chosen point on surface of sphere of radius 1.
; Multiply x,y,z by r to get sphere of radius r.