Formula to make the ends of the arms of a spiral galaxy less dense

Discussion in 'Scripting' started by Zenden1, May 22, 2019.

1. i wan't to make a spiral galaxy in Unity 3D using C# ( i use a derived logarithmic spiral ) but i wan't to set the end of the arms less dens than the middle.

I want that : In my game i have this result actually : Code (CSharp):
1. public int numArms = 5;
2. public float armOffsetMax = 0.5f;
3. public float rotationFactor = 5;
4. public float randomOffsetXY = 0.02f;
5. public float percentStarInCentre = 5;
6.
7.
8.
9. for (int i = 0; i < PixelMath.instanceStarCount; i++)
10.         {
11.             if(type == GalaxyTypes.Spiral)
12.             {
13.                 float distance = Random.value;
14.                 distance = Mathf.Pow (distance, PixelMath.percentStarInCentre / 100) ;
15.
16.
17.                 // Choose an angle between 0 and 2 * PI.
18.                 float angle = Random.value * 2 * Mathf.PI;
19.                 float armOffset = Random.value * PixelMath.armsOffetSetMax;
20.
21.                 armOffset = armOffset - PixelMath.armsOffetSetMax / 2;
22.                 armOffset = armOffset * (1 / distance);
23.
24.                 float squaredArmOffset = Mathf.Pow (armOffset, 2);
25.
26.                 if (armOffset < 0)
27.                     squaredArmOffset = squaredArmOffset * -1;
28.                 armOffset = squaredArmOffset;
29.
30.                 float rotation = distance * PixelMath.rotationFactor;
31.
32.                 // Compute the angle of the arms.
33.                 angle = (int) (angle / armSeparationDistance ) * armSeparationDistance + armOffset + rotation;
34.
35.
36.                 // Convert polar coordinates to 2D cartesian coordinates.
37.                 float starX =  Mathf.Sin (angle) * distance;
38.                 float starZ =  Mathf.Cos (angle) * distance;
39.                 float starY = 0;

Last edited: May 24, 2019
2. up

3. just use falloff mask that modulate density with distance from the center

Zenden1 likes this.
4. Right now you're adding one random star in every iteration of your loop. Create a probability function as prob = 1 - (distance / radius) or whatever falloff you want (square, log, etc). Generate a random number from 0 to 1. If number is more than probabilty then skip to next iteration.

5. Yep I would go with radius from the center.
Further you go, less particles you generate.

Zenden1 likes this.
6. Hi, do you have any link or exemple of that ? I never heard about that and i found nothing possible to be that .

I just have the French College level, So....

7. neoshaman likes this.