Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. private void button7_Click(object sender, EventArgs e)
  2.         {
  3.             ClearForm();
  4.             PreparareForm(-11, 11, -11, 11);
  5.             Random r = new Random();
  6.  
  7.             int n = r.Next(3, 20);
  8.             int m = r.Next(3, n);
  9.             XMid = chart1.Series.Add("Points");
  10.             XMid.ChartType = SeriesChartType.Point;
  11.             List<int> xx = new List<int>();
  12.             List<int> yy = new List<int>();
  13.             for (int i = 0; i < n; i++)
  14.             {
  15.                 int x = r.Next(-10, 10);
  16.                 int y = r.Next(-10, 10);
  17.                 richTextBox1.AppendText("x: " + x + " y: " + y + "\n");
  18.                 XMid.Points.AddXY(x, y);
  19.                 xx.Add(x);
  20.                 yy.Add(y);
  21.             }
  22.  
  23.             X1X2 = chart1.Series.Add("Other Points");
  24.             X1X2.ChartType = SeriesChartType.Point;
  25.             int count = 0;
  26.             for (int i = 0; i < m; i++)
  27.             {
  28.                 double ave = vidutinis(xx, yy);
  29.                 other_points(X1X2, ave, xx, yy, count);
  30.                 count++;
  31.             }
  32.  
  33.  
  34.             //richTextBox1.AppendText("\n" + ave);
  35.  
  36.  
  37.  
  38.         }
  39.  
  40.         private void other_points(Series xx, double ave, List<int> x, List<int> y, int count)
  41.         {
  42.             if (count < 10)
  43.                 xx.Points.AddXY(x[count] + ave, y[count] - ave*2);
  44.             if (count > 10)
  45.                 xx.Points.AddXY(x[count] - ave, y[count] + ave);
  46.         }
  47.  
  48.         private double vidutinis(List<int> x, List<int> y)
  49.         {
  50.             double a = 0;
  51.             for (int i = 0; i < x.Count; i++)
  52.             {
  53.                 for (int k = 0; k < y.Count; k++)
  54.                 {
  55.                     if (i != k)
  56.                         a += Math.Pow((Math.Pow((x[k] - x[i]), 2) + Math.Pow((y[k] - y[i]), 2)), 1 / 2);
  57.                 }
  58.             }
  59.             double ave = a / (x.Count * y.Count);
  60.             return ave;
  61.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement