Beispiel #1
0
        public void SignalwithWhiteNoise(int percent)
        {
            double[] noise     = new double[size];
            Random   rnd       = new Random();
            double   rand_part = 0;
            double   new_rand  = 0.0;

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    rand_part += rnd.NextDouble() * 2 - 1;
                }
                new_rand = rand_part / 10;

                noise_energy += new_rand * new_rand;
                noise[i]      = new_rand * percent / 100;

                rand_part = 0;
            }

            for (UInt16 i = 0; i < size; i++)
            {
                signal[i] = new dot(signal[i].real_amplitude + percent * noise[i], 0, i);
            }
        }
        static void Main(string[] args)
        {
            dot a = new dot
            {
                x = int.Parse(Console.ReadLine()),
                y = int.Parse(Console.ReadLine())
            };

            dot b = new dot
            {
                x = int.Parse(Console.ReadLine()),
                y = int.Parse(Console.ReadLine())
            };

            dot c = new dot
            {
                x = int.Parse(Console.ReadLine()),
                y = int.Parse(Console.ReadLine())
            };

            double len1 = b.length(a);
            double len2 = c.length(a);

            if (len1 < len2)
            {
                Console.WriteLine("B, length = " + len1);
            }
            else
            {
                Console.WriteLine("C, length = " + len2);
            }

            Console.ReadLine(); // пауза для просмотра результата
        }
Beispiel #3
0
        public void SinGen(double ampl, double phase, double samp_freq, UInt16 first, UInt16 last)
        {
            for (UInt16 i = first; i < last; i++)
            {
                bool k    = false;
                dot  temp = new dot(ampl * Math.Sin(phase * i + samp_freq), 0, i);


                for (int j = 0; j < signal.Count; j++)
                {
                    if (signal[j].x_pos == i)
                    {
                        signal[j] = new dot(signal[j].real_amplitude + ampl * Math.Sin(phase * i + samp_freq), 0, i);
                        k         = true;

                        break;
                    }
                }

                if (!k)
                {
                    signal.Add(temp);
                    size++;
                    signal_energy += signal[i].real_amplitude * signal[i].real_amplitude;
                }
            }
        }
Beispiel #4
0
        public List <dot> Corr(int count, int lenght)
        {
            List <dot> temp   = signal;
            List <dot> CRList = new List <dot>();
            double     tmp;
            dot        tmp1;

            for (int m = 0; m < count; m++)
            {
                tmp = 0.0;

                for (int n = 0; n < lenght - m - 1; n++)
                {
                    tmp += temp[n + m].real_amplitude * temp[n].real_amplitude;
                }

                tmp = tmp / (lenght - m);

                tmp1 = new dot(tmp, 0, Convert.ToUInt16(m));

                CRList.Add(tmp1);
            }

            return(CRList);
        }
        static void Main(string[] args)
        {
            dot a = new dot
            {
                x = int.Parse(Console.ReadLine()),
                y = int.Parse(Console.ReadLine())
            };

            if (a.x > 0 && a.y > 0)
            {
                Console.WriteLine("Quarter: I");
            }
            else if (a.x > 0 && a.y < 0)
            {
                Console.WriteLine("Quarter: IV");
            }
            else if (a.x < 0 && a.y < 0)
            {
                Console.WriteLine("Quarter: III");
            }
            else if (a.x < 0 && a.y > 0)
            {
                Console.WriteLine("Quarter: II");
            }

            Console.ReadLine(); // пауза для просмотра результата
        }
    public dot add_dot(float total_time, float duration, callback cb_each, callback when_end)
    {
        dot d = new dot(total_time, duration, cb_each, when_end);

        dots.Add(d.guid, d);
        return(d);
    }
Beispiel #7
0
        //public void SignalGen(int sin_count, double[] _ampl, double[] _phase, double[] _samp_freq, UInt32[] _first, UInt32[] _last)
        //{
        //    for (int i = 0; i < sin_count; i++)
        //    {
        //        SinGen(_ampl[i], _phase[i], _samp_freq[i], _first[i], _last[i]);
        //    }
        //}

        public void SignalwithWhiteNoise(int percent)
        {
            double[] noise     = new double[signal.Count];
            Random   rnd       = new Random();
            double   rand_part = 0;

            for (int i = 0; i < signal.Count; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    rand_part += rnd.NextDouble() * 2 - 1;
                }
                rand_part = rand_part / 10;

                noise_energy += rand_part * rand_part;
                noise[i]      = rand_part;

                rand_part = 0;
            }

            for (int i = 0; i < signal.Count; i++)
            {
                signal[i] = new dot(signal[i].real_amplitude + percent * noise[i], 0, signal[i].x_pos);
            }
        }
 public void cancle_dot(dot d)
 {
     if (dots.ContainsKey(d.guid))
     {
         dots[d.guid].pause();
         dots.Remove(d.guid);
     }
 }
Beispiel #9
0
        public void Fourea(List <dot> sig, int n, int s)
        {
            int    i, j, istep;
            int    m, mmax;
            double r, r1, theta, w_r, w_i, temp_r, temp_i;
            double pi = 3.1415926f;

            r = pi * s;
            j = 0;
            for (i = 0; i < n; i++)
            {
                if (i < j)
                {
                    temp_r = sig[j].real_amplitude;
                    temp_i = sig[j].im_amplitude;

                    sig[j] = new dot(sig[i].real_amplitude, sig[i].im_amplitude, sig[j].x_pos);
                    sig[i] = new dot(temp_r, temp_i, sig[i].x_pos);
                }
                m = n >> 1;
                while (j >= m)
                {
                    j -= m; m = (m + 1) / 2;
                }
                j += m;
            }
            mmax = 1;
            while (mmax < n)
            {
                istep = mmax << 1;
                r1    = r / (double)mmax;
                for (m = 0; m < mmax; m++)
                {
                    theta = r1 * m;
                    w_r   = (double)Math.Cos((double)theta);
                    w_i   = (double)Math.Sin((double)theta);
                    for (i = m; i < n; i += istep)
                    {
                        j      = i + mmax;
                        temp_r = w_r * sig[j].real_amplitude - w_i * sig[j].im_amplitude;
                        temp_i = w_r * sig[j].im_amplitude + w_i * sig[j].real_amplitude;

                        sig[j] = new dot(sig[i].real_amplitude - temp_r, sig[i].im_amplitude - temp_i, sig[j].x_pos);

                        sig[i] = new dot(sig[i].real_amplitude + temp_r, sig[i].im_amplitude + temp_i, sig[i].x_pos);
                    }
                }
                mmax = istep;
            }
            if (s > 0)
            {
                for (i = 0; i < n; i++)
                {
                    sig[i] = new dot(sig[i].real_amplitude / (Convert.ToDouble(n)), sig[i].im_amplitude / (Convert.ToDouble(n)), sig[i].x_pos);
                }
            }
        }
Beispiel #10
0
        public void SqSinGen(double ampl, double samp_freq, double phase, UInt32 first, UInt32 last)
        {
            dot temp;



            for (UInt32 i = 0; i < last - first; i++)
            {
                double a;
                current_phase = phase + samp_freq * i;
                mas_cur_phase.Add(current_phase);

                a              = ampl * Math.Sin(current_phase);
                signal_energy += a * a;

                temp = new dot(a, 0, i);

                signal.Add(temp);
            }
        }
Beispiel #11
0
        public void CosSinGen(double ampl, double samp_freq, double phase, UInt32 first, UInt32 last)
        {
            dot temp;



            for (UInt32 i = 0; i < last - first; i++)
            {
                double a;
                current_phase = phase + samp_freq * i;
                mas_cur_phase.Add(current_phase);
                double coef = 0.54 + 0.46 * Math.Cos(2 * Math.PI * (i - last / 2) / last);

                a              = ampl * Math.Sin(current_phase) * coef;
                signal_energy += a * a;

                temp = new dot(a, 0, i);

                signal.Add(temp);
            }
        }
Beispiel #12
0
        public static List <dot> Finddot()
        {
            List <dot> dots = new List <dot>();
            var        xml  = XElement.Load(@"2ba22002ce3cc736d4db3269451bdc29_export.xml");

            var dotsNode = xml.Descendants("row").ToList();

            dotsNode
            .Where(x => !x.IsEmpty).ToList()
            .ForEach(dotNode =>
            {
                dot o    = new dot();
                o.機構名稱   = dotNode.Element("Col2").Value;
                o.地址縣市別  = dotNode.Element("Col3").Value;
                o.地址鄉鎮市區 = dotNode.Element("Col4").Value;
                o.負責人姓名  = dotNode.Element("Col6").Value;
                o.電話     = dotNode.Element("Col8").Value;
                dots.Add(o);
            });
            return(dots);
        }
Beispiel #13
0
        private void AfterFur_Click(object sender, EventArgs e)
        {
            double energy = 0.0;

            for (UInt16 i = 0; i < l; ++i)
            {
                energy += Math.Sqrt(spisok[i].im_amplitude * spisok[i].im_amplitude + spisok[i].real_amplitude * spisok[i].real_amplitude);
                if (energy >= (full_energy * coef * Convert.ToInt16(NoisePerc.Text) / 100))
                {
                    if (spisok.Count() / 2 < i)
                    {
                        break;
                    }

                    while (i != l - i)
                    {
                        spisok[i + 1]     = new dot(0.0, 0.0, i);
                        spisok[l - i - 1] = new dot(0.0, 0.0, Convert.ToUInt16(l - i - 1));

                        ++i;
                    }
                    break;
                }
            }

            SignGraph.Series[2].Points.Clear();
            forform.Clear();

            SignGraph.Series[2].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
            SignGraph.Series[2].Color     = Color.Red;

            for (int i = 0; i < l; i++)
            {
                double x = spisok[i].x_pos * min_phase;
                double y = Math.Sqrt(spisok[i].im_amplitude * spisok[i].im_amplitude + spisok[i].real_amplitude * spisok[i].real_amplitude);

                SignGraph.Series[2].Points.AddXY(x, y);
            }
        }
Beispiel #14
0
        private void GraphNum_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                int full_length = forform.GetS();
                int count       = Convert.ToInt32(TextL.Text);
                this.SignGraph.Series.Clear();

                //this.SignGraph.Series.Add(new System.Windows.Forms.DataVisualization.Charting.Series()
                //{
                //    Name = "Series" ,
                //    ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line

                //});

                var tmp = new List <dot>();
                tmp.AddRange(corgraphclone);

                for (int j = count - 1; j >= Convert.ToInt32(GraphNum.Text); j--)            //заменяем начиная с конца элементы с нуля
                {
                    tmp[j] = new dot(0, 0, Convert.ToUInt32(j));
                }

                forform.Fourea(tmp, full_length, -1);

                for (int j = 0; j < full_length; j++)
                {
                    int    x;
                    double y;
                    x = j;
                    y = Math.Sqrt(tmp[j].im_amplitude * tmp[j].im_amplitude + tmp[j].real_amplitude * tmp[j].real_amplitude);

                    Console.WriteLine(j + "     " + y);

                    SignGraph.Series[0].Points.AddXY(x, y);
                }
            }
        }
Beispiel #15
0
        public void TrSinGen(double ampl, double samp_freq, double phase, int first, int last)
        {
            dot temp;

            double coef;

            for (int i = 0; i < last - first; i++)
            {
                double a;

                current_phase = phase + samp_freq * i;
                mas_cur_phase.Add(current_phase);
                coef = 1 - 2 * Math.Abs(Convert.ToDouble(i - last / 2) / Convert.ToDouble(last));


                a              = ampl * Math.Sin(current_phase) * coef;
                signal_energy += a * a;

                temp = new dot(a, 0, Convert.ToUInt32(i));

                signal.Add(temp);
            }
        }
Beispiel #16
0
    public List <dot> getDots(List <user> users, int fromYear, int toYear)
    {
        List <dot> dots = new List <dot>();

        foreach (user u in users)
        {
            int    from = fromYear, to = toYear, thisYear = u.createdYear;
            double current = u.initHolding;
            if (to < u.createdYear)
            {
                continue;
            }
            List <transaction> trans = new List <transaction>();
            #region getting the trans
            SqlConnection connection;
            SqlDataReader reader;
            string        commandText = "";
            SqlCommand    command;
            connection  = new SqlConnection(connection_String);
            commandText = String.Format("SELECT * FROM [dbo].[transactions] where fromId = '" + u.id.ToString() + "' or toId = '" + u.id.ToString() + "' order by year");
            command     = new SqlCommand();
            try
            {
                using (connection)
                {
                    connection.Open();
                    command.Connection  = connection;
                    command.CommandText = commandText;
                    reader = command.ExecuteReader();
                    using (reader)
                    {
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                transaction t = new transaction();
                                t.fromId = reader.GetGuid(0);
                                t.toId   = reader.GetGuid(1);
                                t.year   = reader.GetInt32(2);
                                t.amount = reader.GetDouble(3);
                                trans.Add(t);
                            }
                        }
                        else
                        {
                            throw new Exception("There are no rows in transactions");
                        }
                    }
                }
            }
            catch (Exception e)
            {
            }

            #endregion
            dot d = new dot();
            d.user = u;
            d.name = u.fullName;
            Dictionary <int, double> dic = new Dictionary <int, double>();
            dic.Add(u.createdYear, u.initHolding);
            foreach (transaction t in trans)
            {
                if (t.year > to)
                {
                    break;
                }
                if (u.id == t.fromId)
                {
                    current -= t.amount;
                }
                else if (u.id == t.toId)
                {
                    current += t.amount;
                }
                if (dic.ContainsKey(t.year))
                {
                    dic[t.year] = current;
                }
                else
                {
                    dic.Add(t.year, current);
                }
            }
            if (u.createdYear >= from)
            {
                while (from < u.createdYear)
                {
                    d.data.Add(0);
                    from++;
                }
                while (from <= to)
                {
                    if (dic.ContainsKey(from))
                    {
                        d.data.Add(dic[from]);
                    }
                    else
                    {
                        double value = dic[u.createdYear];
                        foreach (KeyValuePair <int, double> pair in dic)
                        {
                            if (from < pair.Key)
                            {
                                break;
                            }
                            value = pair.Value;
                        }
                        d.data.Add(value);
                    }
                    from++;
                }
            }
            else
            {
                while (from <= to)
                {
                    if (dic.ContainsKey(from))
                    {
                        d.data.Add(dic[from]);
                    }
                    else
                    {
                        double value = dic[u.createdYear];
                        foreach (KeyValuePair <int, double> pair in dic)
                        {
                            if (from < pair.Key)
                            {
                                break;
                            }
                            value = pair.Value;
                        }
                        d.data.Add(value);
                    }
                    from++;
                }
            }
            dots.Add(d);
        }
        return(dots);
    }
Beispiel #17
0
 public static string DotNetFramework(in string version = "4.7.2") => Concat(net, version.Replace(dot, Empty));
Beispiel #18
0
 static float dis(dot a, dot b)
 {
     return((a.y - b.y) * (a.y - b.y) + (a.x - b.x) * (a.x - b.x));
 }
Beispiel #19
0
        static void Main(string[] args)
        {
            Console.WriteLine("选择模式:1、判断形状,计算面积;2、随机生成十个形状,计算其面积之和");
            string choose;

            choose = Console.ReadLine();
            switch (choose)
            {
            case "1":


            {
                Console.WriteLine("请输入点集 输入方式为    a,b c,d ...  ");
                string dotstr;
                dotstr = Console.ReadLine();
                dot[]    Dots = new dot[dotstr.Length - dotstr.Replace(",", "").Length];
                string[] dots = dotstr.Split(" ");
                for (int i = 0; i < dots.Length; i++)
                {
                    string[] a = dots[i].Split(",");
                    Dots[i] = new dot(float.Parse(a[0]), float.Parse(a[1]));
                }

                Console.WriteLine("需要判断的形状");
                Console.WriteLine("1、矩形;2、正方形;3、三角形");

                string choice;
                choice = Console.ReadLine();
                switch (choice)
                {
                case "1":
                    Shapes shape1 = ShapeFactory.GetShapes(ShapeTypes.Rectangle, Dots);
                    Console.WriteLine("形状判断结果为:" + shape1.judgeShape());
                    if (shape1.judgeShape())
                    {
                        Console.WriteLine("面积为:" + shape1.getArea());
                    }
                    break;

                case "2":
                    Shapes shape2 = ShapeFactory.GetShapes(ShapeTypes.Square, Dots);
                    Console.WriteLine("形状判断结果为:" + shape2.judgeShape());
                    if (shape2.judgeShape())
                    {
                        Console.WriteLine("面积为:" + shape2.getArea());
                    }
                    break;

                case "3":
                    Shapes shape3 = ShapeFactory.GetShapes(ShapeTypes.Triangle, Dots);
                    Console.WriteLine("形状判断结果为:" + shape3.judgeShape());
                    if (shape3.judgeShape())
                    {
                        Console.WriteLine("面积为:" + shape3.getArea());
                    }
                    break;

                default: Console.WriteLine("无该选项"); break;
                }
                break;
            }

            case "2":
            {
                Shapes[] shapes = new Shapes[10];
                float    x, y;
                dot[]    Dots1 = new dot[4];
                dot[]    Dots2 = new dot[3];
                Console.WriteLine("形状生成中...");
                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine((i + 1) + "...");
                    Random ra  = new Random();
                    int    num = ra.Next(1, 4);
                    switch (num)
                    {
                    case 1:
                        x         = ra.Next(1, 40);
                        y         = ra.Next(1, 40);
                        Dots1[0]  = new dot(x, y);
                        x         = ra.Next(1, 40);
                        y         = ra.Next(1, 40);
                        Dots1[2]  = new dot(x, y);
                        Dots1[1]  = new dot(Dots1[0].y, Dots1[2].x);
                        Dots1[3]  = new dot(Dots1[0].x, Dots1[2].y);
                        shapes[i] = ShapeFactory.GetShapes(ShapeTypes.Rectangle, Dots1);
                        break;

                    case 2:
                        x         = ra.Next(1, 40);
                        y         = ra.Next(1, 40);
                        Dots1[0]  = new dot(x, y);
                        x         = ra.Next(1, 40);
                        Dots1[2]  = new dot(x, y + x - Dots1[0].x);
                        Dots1[1]  = new dot(Dots1[0].y, Dots1[2].x);
                        Dots1[3]  = new dot(Dots1[0].x, Dots1[2].y);
                        shapes[i] = ShapeFactory.GetShapes(ShapeTypes.Square, Dots1);
                        break;

                    default:
                        x         = ra.Next(1, 40);
                        y         = ra.Next(1, 40);
                        Dots2[0]  = new dot(x, y);
                        x         = ra.Next(1, 40);
                        y         = ra.Next(1, 40);
                        Dots2[1]  = new dot(x, y);
                        x         = ra.Next(1, 40);
                        y         = ra.Next(1, 40);
                        Dots2[2]  = new dot(x, y);
                        shapes[i] = ShapeFactory.GetShapes(ShapeTypes.Triangle, Dots2);
                        break;
                    }
                    //for (int j = 0; j < 4; j++)
                    //    Console.WriteLine(Dots2[1].x);
                }
                Console.WriteLine("生成完成,计算面积总和...");
                float sum = 0;
                for (int i = 0; i < 10; i++)
                {
                    sum += shapes[i].getArea();
                }
                Console.WriteLine("面积总和为:" + sum);
                break;
            }

            default: Console.WriteLine("无该选项"); break;
            }
        }
Beispiel #20
0
        private void Fourea_Click(object sender, EventArgs e)
        {
            int full_length = forform.GetS();

            int count = Convert.ToInt16(TextL.Text);

            //for (int i = 0; i < count + 1; i++)
            //{
            //    SignGraph.Series[i].Points.Clear();
            //}

            for (int i = 0; i < 2; i++)
            {
                SignGraph.Series[i].Points.Clear();
            }


            fo = new double[count];
            int[] itr = new int[count];

            for (int i = 0; i < count; i++)
            {
                var tmp = new List <dot>();
                tmp.AddRange(corgraphclone);

                for (int j = count - 1; j >= count - i; j--)            //заменяем начиная с конца элементы с нуля
                {
                    tmp[j] = new dot(0, 0, Convert.ToUInt32(count - i - 1));
                }

                forform.Fourea(tmp, full_length, -1);           //хуячим Фурьём

                double max = 0.0;

                for (int j = 0; j < full_length / 2; j++)
                {
                    if (Math.Sqrt(tmp[j].im_amplitude * tmp[j].im_amplitude + tmp[j].real_amplitude * tmp[j].real_amplitude) > max)
                    {
                        max = Math.Sqrt(tmp[j].im_amplitude * tmp[j].im_amplitude + tmp[j].real_amplitude * tmp[j].real_amplitude); itr[i] = j;
                    }
                }

                for (int j = 0; j < full_length; j++)
                {
                    int    x;
                    double y;
                    x = j;
                    y = Math.Sqrt(tmp[j].im_amplitude * tmp[j].im_amplitude + tmp[j].real_amplitude * tmp[j].real_amplitude);

                    //SignGraph.Series[i].Points.AddXY(x, y);
                }


                fo[i] = (itr[i]) * 2 / Convert.ToDouble(full_length);
            }


            Array.Reverse(fo);
            Array.Reverse(itr);


            for (int i = 0; i < count; i++)
            {
                Console.WriteLine(i + " itr  " + itr[i] + "    fo   " + fo[i]);
            }
        }
 public double length(dot n)
 {
     return(Math.Sqrt(Math.Pow(n.x - x, 2) + Math.Pow(n.y - y, 2)));
 }