Get random orientations in 3D from a uniform orientation distribution.
vecs = sphrand(N) vecs = sphrand(N,k) [phi, theta] = sphrand(...)
sphrand
does in a random way what
sphgrid does
more systematically. It calculates N
points on the unit sphere.
In the limit of these points are evenly
distributed, since the underlying distribution is a uniform one.
If k
is specified, it determines the number of octants over which
to generate the points. It can be 1 (one octant), 2 (two octants), 4
(upper hemisphere) or 8 (whole sphere). If absent, k = 1
is the
default.
The output is either an 3xN array of norm 1 cartesian
vectors vecs
pointing from the origin to the sphere surface,
or in terms of polar angles phi
and theta
.
phi
denotes the counterclockwise angle between the x axis
and the projection of a vector onto the xy plane (azimuth),
theta
is the angle between a vector and the z axis
(colatitude, elevation complement).
Both theta
and phi
are in radians.
The command
[phi,theta] = sphrand(10000,8);
generates 10000 points uniformly distributed over the whole sphere. The plot
plot(phi*180/pi,theta*180/pi,'.'); set(gca,'YDir','reverse'); axis tight xlabel('phi'); ylabel('theta');
shows that in a theta
vs. phi
projection
there is reduced point density around the north and south poles.
ang2vec, vec2ang, sphgrid, sphtri