Exemplo n.º 1
0
 public Form1()
 {
     InitializeComponent();
     pen      = new Pen(Color.Black, 1);
     graphics = panel1.CreateGraphics();
     graphics.TranslateTransform(400, 400);
     random    = new Random(144);
     linePen   = new Pen(Color.Black);
     centroizi = new Punct[random.Next(2, 9)];
     for (int i = 0; i < centroizi.Length; i++)
     {
         centroizi[i]      = new Punct();
         centroizi[i].x    = random.Next(-350, 350);
         centroizi[i].y    = random.Next(-350, 350);
         centroizi[i].zona = i;
         centroizi[i].c    = colors[i];
     }
 }
Exemplo n.º 2
0
 private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
 {
     using (var sr = new System.IO.StreamReader(openFileDialog1.FileName))
     {
         String line = sr.ReadLine();
         int    n    = 0;
         if (int.TryParse(line, out n))
         {
             puncte = new Punct[n];
             for (int i = 0; i < n; i++)
             {
                 line      = sr.ReadLine();
                 puncte[i] = new Punct();
                 var s = line.Split(' ');
                 puncte[i].c = Color.Black;
                 puncte[i].x = int.Parse(s[1]);
                 puncte[i].y = int.Parse(s[2]);
             }
         }
     }
     deseneazaPunctele(puncte);
 }
Exemplo n.º 3
0
 private double distantaManhattan(Punct a, Punct b)
 {
     return(Math.Abs(a.x - b.x) + Math.Abs(a.y - b.y));
 }
Exemplo n.º 4
0
        private double distantaCosinus(Punct a, Punct b)
        {
            double x1 = a.x / 400.0, y1 = a.y / 400.0, x2 = b.x / 400.0, y2 = b.y / 400.0;

            return((x1 * x2 + y1 * y2) / (double)((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2)));
        }
Exemplo n.º 5
0
 private double distantaEuclidiana(Punct a, Punct b)
 {
     return(Math.Sqrt(Math.Pow(a.x - b.x, 2) + Math.Pow(a.y - b.y, 2)));
 }