Exemplo n.º 1
0
 private static void MoveK(int k, List <k> ks, ref bool haveChange)
 {
     bool[] kHaveChange = new bool[k];
     for (int i = 0; i < ks.Count; i++)
     {
         twoDimensionPostion oldKPos = ks[i].pos;
         //cal avg pos of children
         int totalx = 0;
         int totaly = 0;
         for (int n = 0; n < ks[i].children.Count; n++)
         {
             totalx += ks[i].children[n].pos.x;
             totaly += ks[i].children[n].pos.y;
         }
         twoDimensionPostion newKPos = new twoDimensionPostion(ks[i].children.Count > 0?totalx / ks[i].children.Count:totalx, ks[i].children.Count > 0? totaly / ks[i].children.Count:totaly);
         ks[i].pos      = newKPos;
         ks[i].children = new List <star>();
         if (oldKPos.x != newKPos.x || oldKPos.y != newKPos.y)
         {
             kHaveChange[i] = true;
         }
         else
         {
             kHaveChange[i] = false;
         }
     }
     haveChange = false;
     for (int i = 0; i < kHaveChange.Length; i++)
     {
         if (kHaveChange[i])
         {
             haveChange = true;
         }
     }
 }
Exemplo n.º 2
0
        private static double calDistance(twoDimensionPostion posA, twoDimensionPostion posB)
        {
            double a = posA.x - posB.x;
            double b = posA.y - posB.y;
            double c = Math.Sqrt(a * a + b * b);

            return(c);
        }
Exemplo n.º 3
0
        public static List <k> GenRandomK(int SideLength, int k)
        {
            List <k> ks = new List <k>();

            for (int i = 0; i < k; i++)
            {
                int kx = rand.Next(SideLength);
                int ky = rand.Next(SideLength);
                twoDimensionPostion kp = new twoDimensionPostion(kx, ky);
                ks.Add(new k(kp));
            }

            return(ks);
        }
Exemplo n.º 4
0
        public static List <star> generateStarGrid(int SideLength, int density)
        {
            if (density > (SideLength * SideLength))
            {
                throw new Exception("density cannot more than size.");
            }
            List <star> stars = new List <star>();

            while (stars.Count < density)
            {
                twoDimensionPostion newPos = new twoDimensionPostion(rand.Next(SideLength), rand.Next(SideLength));
                star s = new star(newPos);
                stars.Add(s);
            }
            return(stars);
        }
Exemplo n.º 5
0
 public star(twoDimensionPostion pos)
 {
     this.pos = pos;
 }