Placing objects at a radius

Blitz3D Forums/Blitz3D Programming/Placing objects at a radius

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

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.