File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ var RandomXY = function ( vector , scale )
2+ {
3+ if ( scale === undefined ) { scale = 1 ; }
4+
5+ var r = Math . random ( ) * 2 * Math . PI ;
6+
7+ vector . x = Math . cos ( r ) * scale ;
8+ vector . y = Math . sin ( r ) * scale ;
9+
10+ return vector ;
11+ } ;
12+
13+ module . exports = RandomXY ;
Original file line number Diff line number Diff line change 1+ // Position Vector randomly in a spherical area defined by the given radius
2+ var RandomXYZ = function ( vector , radius )
3+ {
4+ if ( radius === undefined ) { radius = 1 ; }
5+
6+ var r = Math . random ( ) * 2 * Math . PI ;
7+ var z = ( Math . random ( ) * 2 ) - 1 ;
8+ var zScale = Math . sqrt ( 1 - z * z ) * radius ;
9+
10+ vector . x = Math . cos ( r ) * zScale ;
11+ vector . y = Math . sin ( r ) * zScale ;
12+ vector . z = z * radius ;
13+
14+ return vector ;
15+ } ;
16+
17+ module . exports = RandomXYZ ;
Original file line number Diff line number Diff line change 1+ var RandomXYZW = function ( vector , scale )
2+ {
3+ if ( scale === undefined ) { scale = 1 ; }
4+
5+ // Not spherical; should fix this for more uniform distribution
6+ vector . x = ( Math . random ( ) * 2 - 1 ) * scale ;
7+ vector . y = ( Math . random ( ) * 2 - 1 ) * scale ;
8+ vector . z = ( Math . random ( ) * 2 - 1 ) * scale ;
9+ vector . w = ( Math . random ( ) * 2 - 1 ) * scale ;
10+
11+ return vector ;
12+ } ;
13+
14+ module . exports = RandomXYZW ;
Original file line number Diff line number Diff line change @@ -198,18 +198,6 @@ var Vector2 = new Class({
198198 this . x = 0 ;
199199 this . y = 0 ;
200200
201- return this ;
202- } ,
203-
204- random : function ( scale )
205- {
206- if ( scale === undefined ) { scale = 1 ; }
207-
208- var r = Math . random ( ) * 2 * Math . PI ;
209-
210- this . x = Math . cos ( r ) * scale ;
211- this . y = Math . sin ( r ) * scale ;
212-
213201 return this ;
214202 }
215203
Original file line number Diff line number Diff line change @@ -327,22 +327,6 @@ var Vector3 = new Class({
327327 return this . project ( invProjectionView ) ;
328328 } ,
329329
330- // Position Vector randomly in a spherical area defined by the given radius
331- random : function ( radius )
332- {
333- if ( radius === undefined ) { radius = 1 ; }
334-
335- var r = Math . random ( ) * 2 * Math . PI ;
336- var z = ( Math . random ( ) * 2 ) - 1 ;
337- var zScale = Math . sqrt ( 1 - z * z ) * radius ;
338-
339- this . x = Math . cos ( r ) * zScale ;
340- this . y = Math . sin ( r ) * zScale ;
341- this . z = z * radius ;
342-
343- return this ;
344- } ,
345-
346330 reset : function ( )
347331 {
348332 this . x = 0 ;
Original file line number Diff line number Diff line change @@ -246,19 +246,6 @@ var Vector4 = new Class({
246246 return this ;
247247 } ,
248248
249- random : function ( scale )
250- {
251- if ( scale === undefined ) { scale = 1 ; }
252-
253- // Not spherical; should fix this for more uniform distribution
254- this . x = ( Math . random ( ) * 2 - 1 ) * scale ;
255- this . y = ( Math . random ( ) * 2 - 1 ) * scale ;
256- this . z = ( Math . random ( ) * 2 - 1 ) * scale ;
257- this . w = ( Math . random ( ) * 2 - 1 ) * scale ;
258-
259- return this ;
260- } ,
261-
262249 reset : function ( )
263250 {
264251 this . x = 0 ;
Original file line number Diff line number Diff line change @@ -29,6 +29,9 @@ module.exports = {
2929 MinSub : require ( './MinSub' ) ,
3030 Percent : require ( './Percent' ) ,
3131 RadToDeg : require ( './RadToDeg' ) ,
32+ RandomXY : require ( './RandomXY' ) ,
33+ RandomXYZ : require ( './RandomXYZ' ) ,
34+ RandomXYZW : require ( './RandomXYZW' ) ,
3235 Rotate : require ( './Rotate' ) ,
3336 RotateAround : require ( './RotateAround' ) ,
3437 RotateAroundDistance : require ( './RotateAroundDistance' ) ,
You can’t perform that action at this time.
0 commit comments