sphrand
 
 
 

Returns a random vector value that exists within a spherical or ellipsoidal region of your choice. An ellipsoid is a sphere scaled along its X-, Y- or Z-axes.

vector sphrand(float radius)

vector sphrand(vector vector)

radius is the radius of a sphere in which the returned vector exists.

vector is the radius of an ellipsoid along the X-, Y-, and Z-axis.

To control the random values returned by this function, see seed.

Example 1

sphrand(1)

Returns a vector whose randomly selected coordinates reside within an imaginary sphere centered at the origin and with a radius of 1. An example returned vector is <<0.444, -0.427, 0.764>>.

Example 2

sphrand(<<2,1,1>>)

Returns a vector whose coordinates reside within an ellipsoid centered at the origin and with a radius of 2 along the X-axis, 1 along the Y-axis, and 1 along the Z-axis.

You can use the sphrand function, for example, to create a cluster of 500 particles randomly positioned within an ellipsoid having a radius of 2 in the X-axis, 1 in the Y-axis, and 1 in the Z-axis.

To create a particle ellipsoid:

  1. Select Particles > Particle Tool > .
  2. Enter 500 for Number of Particles, and 1 for Maximum Radius.
  3. Click the mouse somewhere in the workspace to position the particles.
  4. Select the particle shape node of the particle object in the Expression Editor.
  5. Turn on Creation.
  6. Enter this expression:
    position = sphrand(<<2,1,1>>);
    

    Maya executes the expression once for each particle. It gives each particle a different random position around the origin within the ellipsoid specified by <<2,1,1>>.