Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Point Cloud

Discussion in 'Assets and Asset Store' started by Arkhivrag, Jan 5, 2015.

  1. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,932
    Last edited: Feb 14, 2015
    moure likes this.
  2. Play_Edu

    Play_Edu

    Joined:
    Jun 10, 2012
    Posts:
    722
    nice 1
     
  3. dyox

    dyox

    Joined:
    Aug 19, 2011
    Posts:
    619
    Awesome !
    It can be excellent for galaxies :





    Code (CSharp):
    1. PointF[] points;
    2.  
    3. public PointF[] GenerateGalaxy(int numOfStars, int numOfArms, float spin, double armSpread, double starsAtCenterRatio)
    4. {
    5.     List<PointF> result = new List<PointF>(numOfStars);
    6.     for (int i = 0; i < numOfArms; i++)
    7.     {
    8.         result.AddRange(GenerateArm(numOfStars / numOfArms, (float)i / (float)numOfArms, spin, armSpread, starsAtCenterRatio));
    9.     }
    10.     return result.ToArray();
    11. }
    12.  
    13. public PointF[] GenerateArm(int numOfStars, float rotation, float spin, double armSpread, double starsAtCenterRatio)
    14. {
    15.     PointF[] result = new PointF[numOfStars];
    16.     Random r = new Random();
    17.  
    18.     for (int i = 0; i < numOfStars; i++)
    19.     {
    20.         double part = (double)i / (double)numOfStars;
    21.         part = Math.Pow(part, starsAtCenterRatio);
    22.  
    23.         float distanceFromCenter = (float)part;
    24.         double position = (part * spin + rotation) * Math.PI * 2;
    25.  
    26.         double xFluctuation = (Pow3Constrained(r.NextDouble()) - Pow3Constrained(r.NextDouble())) * armSpread;
    27.         double yFluctuation = (Pow3Constrained(r.NextDouble()) - Pow3Constrained(r.NextDouble())) * armSpread;
    28.  
    29.         float resultX = (float)Math.Cos(position) * distanceFromCenter / 2 + 0.5f + (float)xFluctuation;
    30.         float resultY = (float)Math.Sin(position) * distanceFromCenter / 2 + 0.5f + (float)yFluctuation;
    31.  
    32.         result[i] = new PointF(resultX, resultY);
    33.     }
    34.  
    35.     return result;
    36. }
    37.  
    38. public static double Pow3Constrained(double x)
    39. {
    40.     double value = Math.Pow(x - 0.5, 3) * 4 + 0.5d;
    41.     return Math.Max(Math.Min(1, value), 0);
    42. }
    43.  
    44. Example:
    45.  
    46. points = GenerateGalaxy(80000, 2, 3f, 0.1d, 3);
     
    Arkhivrag likes this.
  4. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    112
    That was my immediate thought, I remember doing something similar years ago.

    I'm looking forward to this Arkhivrag!
     
  5. dominikvr

    dominikvr

    Joined:
    Jun 23, 2019
    Posts:
    1
    Is this project still alive?
     
  6. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,932