Create circle with fuzzy edge made of individual random particles

What works with the circle, works a bit more complicated with the sphere.
You have to distribute the angles evenly and then multiply the unit sphere by rand.

try SphereWithRandomPointsl

see also GitHub - hofk/threejsResources: Resources for three.js

function PointsSphere( n, dri, r, dro ) { 
    
     // n: points count,  dri: inner difference , r: radius main, dro: outer difference  
    
    const pts = [];
   
    for( let i = 0; i < n ; i++){
    
            const inout = ( Math.random( ) - 0.5 ) * 2;
            const lim = ( inout >= 0 ? dro : dri );
            const rand = r + Math.pow( Math.random( ), 3 ) * lim * inout;
            
            const θ = Math.PI * 2 * Math.random( );
            const φ = Math.acos( 2 *  Math.random( ) - 1 );
            
            const ps = new THREE.Vector3( Math.cos( θ ) * Math.sin( φ ),  Math.sin( θ ) * Math.sin( φ ),  Math.cos( φ ) );
            pts.push( ps.multiplyScalar( rand ) );
            
    }
    
    const geometry = new THREE.BufferGeometry( ).setFromPoints( pts );
    
    return geometry;
    
}
1 Like