示例#1
0
        private void Button4_Click(object sender, EventArgs e)
        {
            TestGraph dothi = new TestGraph();

            Label[] diem = new Label[700];

            if (Math.Round(a, 3) == 1)
            {
                soa = "";
            }
            else
            {
                soa = Math.Round(a, 3).ToString();
            }
            if (b > 0)
            {
                if (Math.Round(b, 3) == 1)
                {
                    sob = "+ ";
                }
                else
                {
                    sob = "+ " + Math.Round(b, 3).ToString();
                }
            }
            if (b < 0)
            {
                if (Math.Round(b, 3) == -1)
                {
                    sob = "- ";
                }
                else
                {
                    sob = "- " + Math.Round(-b, 3) + "";
                }
            }
            if (Math.Round(m, 3) == 1)
            {
                som = "";
            }
            else
            {
                som = Math.Round(m, 3).ToString();
            }
            if (n > 0)
            {
                son = "+ " + Math.Round(n, 3);
            }
            if (n < 0)
            {
                son = "- " + Math.Round(-n, 3);
            }
            soc = Math.Round(c, 3) + "";

            for (int i = 300; i < 601; i++)
            {
                diem[i] = new Label();
                double x = i - 300;
                diem[i].Size = new Size(3, 3);
                int y = (int)Math.Round(30 * (a * Math.Sin(m * (x / 30) + n) + b * Math.Cos(m * (x / 30) + n) - c));
                diem[i].Location  = new Point(i - 1, 299 - y);
                diem[i].BackColor = Color.Blue;
                if (300 - y - 1 < 601)
                {
                    dothi.Controls.Add(diem[i]);
                }

                diem[299] = new Label();
                int y1, y2, tm;
                y1 = diem[i].Location.Y;
                y2 = diem[i - 1].Location.Y;
                if (y1 < y2)
                {
                    tm = y2;
                    y2 = y1;
                    y1 = tm;
                }
                if (Math.Abs(y1 - y2) > 3 && i != 300 && y1 < 700 && y2 > -200)
                {
                    Label[] them = new Label[700];
                    if (y2 < 10)
                    {
                        y2 = 10;
                    }
                    if (y1 > 590)
                    {
                        y1 = 590;
                    }
                    for (int j = y2; j < y1; j++)
                    {
                        them[j]           = new Label();
                        them[j].BackColor = Color.Blue;
                        them[j].Size      = new Size(3, 3);
                        them[j].Location  = new Point(i - 1, j - 1);
                        dothi.Controls.Add(them[j]);
                    }
                }
            }

            for (int i = 300; i > 10; i--)
            {
                diem[i] = new Label();
                double x = i - 300;
                diem[i].Size = new Size(3, 3);
                int y = (int)Math.Round(30 * (a * Math.Sin(m * (x / 30) + n) + b * Math.Cos(m * (x / 30) + n) - c));
                diem[i].Location  = new Point(i - 1, 299 - y);
                diem[i].BackColor = Color.Blue;
                if (300 - y - 1 < 601)
                {
                    dothi.Controls.Add(diem[i]);
                }

                int y1, y2, tm;
                y1 = diem[i].Location.Y;
                y2 = diem[i + 1].Location.Y;
                if (y1 < y2)
                {
                    tm = y2;
                    y2 = y1;
                    y1 = tm;
                }
                if (Math.Abs(y1 - y2) > 3 && i != 300 && y1 < 700 && y2 > -200)
                {
                    Label[] them = new Label[700];
                    if (y2 < 10)
                    {
                        y2 = 10;
                    }
                    if (y1 > 590)
                    {
                        y1 = 590;
                    }
                    for (int j = y2; j < y1; j++)
                    {
                        them[j]           = new Label();
                        them[j].BackColor = Color.Blue;
                        them[j].Size      = new Size(3, 3);
                        them[j].Location  = new Point(i - 1, j - 1);
                        dothi.Controls.Add(them[j]);
                    }
                }
            }
            for (int i = 1; i < 20; i++)
            {
                lg[i]          = new Label();
                lg[i].Text     = "";
                lg[i].Font     = new Font("VNF-Comic Sans", 12);
                lg[i].AutoSize = true;
            }

            dothi.vetruc();

            lg[1].Text     = "Đồ thị hàm số y = " + soa + "sin( " + som + "x " + son + " ) " + sob + "cos( " + som + "x" + son + " ) = " + soc;;
            lg[1].Location = new Point(30, 610);

            for (int i = 1; i < 20; i++)
            {
                dothi.Controls.Add(lg[i]);
            }

            dothi.ShowDialog();
        }
示例#2
0
        private void Button4_Click(object sender, EventArgs e)
        {
            TestGraph dothi = new TestGraph();

            Label[] diem = new Label[700];

            if (a > 0)
            {
                if (Math.Round(a, 3) != 1)
                {
                    soa = Math.Round(a, 3) + "";
                }
            }
            if (a < 0)
            {
                if (Math.Round(a, 3) != -1)
                {
                    soa = "-" + Math.Round(-a, 3) + "";
                }
                else
                {
                    soa = "- ";
                }
            }
            if (b > 0)
            {
                if (Math.Round(b, 3) != 1)
                {
                    sob = " + " + Math.Round(b, 3);
                }
                else
                {
                    sob = "+ ";
                }
            }
            if (b < 0)
            {
                if (Math.Round(b, 3) != -1)
                {
                    sob = "- " + Math.Round(-b, 3);
                }
                else
                {
                    sob = "- ";
                }
            }
            if (c > 0)
            {
                soc = "+ " + Math.Round(c, 3);
            }
            if (c < 0)
            {
                soc = "- " + Math.Round(-c, 3);
            }

            for (int i = 300; i < 601; i++)
            {
                diem[i] = new Label();
                double x = i - 300;
                if (radioButton1.Checked)
                {
                    x = Math.Sin(x / 30);
                }
                if (radioButton2.Checked)
                {
                    x = Math.Cos(x / 30);
                }
                int y = (int)Math.Round(30 * (a * (x * x + (k * k) / (x * x)) + b * (x + k / x) + c));
                diem[i].Size      = new Size(3, 3);
                diem[i].Location  = new Point((int)i - 1, 300 - y - 1);
                diem[i].BackColor = Color.Blue;
                if (300 - y - 1 < 601)
                {
                    dothi.Controls.Add(diem[i]);
                }

                diem[299] = new Label();
                int y1, y2, tm;
                y1 = diem[i].Location.Y;
                y2 = diem[i - 1].Location.Y;
                if (y1 < y2)
                {
                    tm = y2;
                    y2 = y1;
                    y1 = tm;
                }
                if (Math.Abs(y1 - y2) > 3 && i != 300 && y1 < 700 && y2 > -200)
                {
                    Label[] them = new Label[700];
                    if (y2 < 10)
                    {
                        y2 = 10;
                    }
                    if (y1 > 590)
                    {
                        y1 = 590;
                    }
                    for (int j = y2; j < y1; j++)
                    {
                        them[j]           = new Label();
                        them[j].BackColor = Color.Blue;
                        them[j].Size      = new Size(3, 3);
                        them[j].Location  = new Point(i - 1, j - 1);
                        dothi.Controls.Add(them[j]);
                    }
                }
            }

            for (int i = 300; i > 10; i--)
            {
                diem[i] = new Label();
                double x = i - 300;
                if (radioButton1.Checked)
                {
                    x = Math.Sin(x / 30);
                }
                if (radioButton2.Checked)
                {
                    x = Math.Cos(x / 30);
                }
                int y = (int)Math.Round(30 * (a * (x * x + (k * k) / (x * x)) + b * (x + k / x) + c));
                diem[i].Size      = new Size(3, 3);
                diem[i].Location  = new Point((int)i - 1, 300 - y - 1);
                diem[i].BackColor = Color.Blue;
                if (300 - y - 1 < 601)
                {
                    dothi.Controls.Add(diem[i]);
                }

                int y1, y2, tm;
                y1 = diem[i].Location.Y;
                y2 = diem[i + 1].Location.Y;
                if (y1 < y2)
                {
                    tm = y2;
                    y2 = y1;
                    y1 = tm;
                }
                if (Math.Abs(y1 - y2) > 3 && i != 300 && y1 < 700 && y2 > -200)
                {
                    Label[] them = new Label[700];
                    if (y2 < 10)
                    {
                        y2 = 10;
                    }
                    if (y1 > 590)
                    {
                        y1 = 590;
                    }
                    for (int j = y2; j < y1; j++)
                    {
                        them[j]           = new Label();
                        them[j].BackColor = Color.Blue;
                        them[j].Size      = new Size(3, 3);
                        them[j].Location  = new Point(i - 1, j - 1);
                        dothi.Controls.Add(them[j]);
                    }
                }
            }

            dothi.vetruc();

            dothi.ShowDialog();
        }