Vector3 Spiral( float dist, float spacing ) {
float rad = Mathf.Sqrt( dist / (Mathf.PI*spacing ));
float angle = Mathf.PI * 2.0f * rad;
Vector3 retVal = Vector3.zero;
retVal.x = spacing * rad * Mathf.Sin( angle );
retVal.z = spacing * rad * Mathf.Cos( angle );
return retVal;
}
'dist' is the distance along the line of the spiral from the origin, and 'spacing' is how far apart you want the coils of the spiral to be from each other (this spiral has the handy attribute of maintaining a constant radial distance between each concentric coil.)To achieve an even distribution of points, increment the distance param by the value of spacing - that way points will be equally distant form their neighbours on the line as they are from the neighbouring coils.
Here is a screen shot of the points generated by calling Spiral( dist, 1.0f ) with dist = [0,1,2,3...] As you can see, the unit spheres are packed pretty close to 1 unit apart:
Changing the spacing to 2.0f and iterating Spiral( dist, 2.0f) with dist = [0,2,4,6,8...] will lead to each of the unit spheres having 1 unit's space between them:
...Spirals!
No comments:
Post a Comment