Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C# by Insi ( 16 years ago )
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Kursovaya
{
    public partial class formMain : Form
    {
        Pen penAxis;        
        float fShiftX, fShiftY;
        float fZoomX, fZoomY;
        bool bFirst;
        float tmin, tmax;
        int iValueX, iValueY;
        public formMain()
        {
            InitializeComponent();
            iValueX = trackBarMoveX.Value;
            iValueY = trackBarMoveY.Value;
            penAxis = new Pen(Color.GreenYellow, 3);
            fZoomX = 1;
            fZoomY = 1;
            bFirst = true;
            tmin = 0;
            tmax = 0;
        }
        //Метод анализирующий функцию
        private void findParametrs()
        {
            double x,y,t;
            double x0 = (Math.Sin(2 * tmin + 1) * Math.Cos(3 * tmin)),
                  y0 = (Math.Sin(2 * tmin + 1) - Math.Sin(3 * tmin)),
                    x1 = 0, y1 = 0;
            for (t = tmin; t <= tmax; t += 0.00001)
            {
                x = (Math.Sin(2 * t + 1) * Math.Cos(3 * t));
                y = (Math.Sin(2 * t + 1) - Math.Sin(3 * t));
                // ПЕРЕСЕЧЕНИЕ С Х
                if ((x0 >= 0 && x <= 0) || x >= 0 && x0 <= 0)
                    textBoxCrossX.Text = string.Format("{0} ({1} ; {2})\r\n", textBoxCrossX.Text, 0, Math.Round(y, 3));
                // ПЕРЕСЕЧЕНИЕ С Y
                if ((y0 >= 0 && y <= 0) || y >= 0 && y0 <= 0)
                    textBoxCrossY.Text = string.Format("{0} ({1} ; {2})\r\n", textBoxCrossY.Text, Math.Round(x, 3), 0);
                // МИНИМУМЫ
                if(y0<y1 && y0<y)
                    textBoxMin.Text = string.Format("{0} ({1} ; {2})\r\n", textBoxMin.Text, Math.Round(x0, 3), Math.Round(y0, 3));
                // МАКСИМУМЫ
                if (y0 > y && y0 > y1)
                    textBoxMax.Text = string.Format("{0} ({1} ; {2})\r\n", textBoxMax.Text, Math.Round(x0, 3), Math.Round(y0, 3));
                x1 = x0;
                y1 = y0;
                x0 = x;
                y0 = y;
            }
        }
        // Функция рисующая координатную сетку и расставляющая значения на осях
        private void paintLines(PaintEventArgs e)
        {
            float fHeight = panelCoordinateSystem.Height;
            float fWidth = panelCoordinateSystem.Width;
            float tempY, tempX;                                   
            int iTempNum=0;
            Font labelFont = new Font("Arial", 12);
            SolidBrush myBrush = new SolidBrush(Color.Coral);
            Pen penNet = new Pen(Color.Green, (float)0.5);
            if (this.checkBoxNet.Checked) { penNet.Color = Color.Green; }
            else penNet.Color = Color.Transparent;
            // Сетка оси Y
            tempY = 0;
            while (tempY < fHeight - fShiftY)
            {
                e.Graphics.DrawLine(penNet, 0, (fWidth / 2 + fShiftY) + tempY, fWidth, (fHeight / 2 + fShiftY) + tempY);
                e.Graphics.DrawString(string.Format("{0}", -iTempNum * 0.5), labelFont, myBrush, (fWidth / 2 + fShiftX), (fHeight / 2 + fShiftY) + tempY);
                iTempNum++;
                tempY += 80*fZoomY;         
            }
            iTempNum = 0;
            tempY = 0;            
            while (fHeight+fShiftY - tempY > 0)
            {
                e.Graphics.DrawLine(penNet, 0, (fWidth / 2 + fShiftY) - tempY, fWidth, (fHeight / 2 + fShiftY) - tempY);
                e.Graphics.DrawString(string.Format("{0}", iTempNum * 0.5), labelFont, myBrush, (fWidth / 2 + fShiftX), (fHeight / 2 + fShiftY) - tempY);
                iTempNum++;
                tempY += 80*fZoomY;
            }
            // Сетка оси X
            tempX = 0;
            iTempNum = 0;
            while (tempX < fWidth - fShiftX)
            {
                e.Graphics.DrawLine(penNet, (fWidth / 2 + fShiftX) + tempX, 0, (fWidth / 2 + fShiftX) + tempX, fHeight);
                e.Graphics.DrawString(string.Format("{0}", iTempNum * 0.5), labelFont, myBrush, (fWidth / 2 + fShiftX) + tempX, fHeight / 2 + fShiftY);
                iTempNum++;
                tempX += 80 * fZoomX;

            }
            tempX = 0;
            iTempNum = 0;
            while (fWidth+fShiftX - tempX > 0)
            {
                e.Graphics.DrawLine(penNet, (fWidth / 2 + fShiftX) - tempX, 0, (fWidth / 2 + fShiftX) - tempX, fHeight);
                e.Graphics.DrawString(string.Format("{0}", iTempNum * 0.5), labelFont, myBrush, (fWidth / 2 + fShiftX) - tempX, fHeight / 2 + fShiftY);
                iTempNum++;
                tempX += 80 * fZoomX;
            }
        }
        //Функция строаящая график
        private void paintGraph(PaintEventArgs e)
        {            
            float x;
            float y;
            double t;
            Pen myPen = new Pen(Color.White, 1);
            SolidBrush myBrush = new SolidBrush(Color.White);
            float x0 = panelCoordinateSystem.Width / 2 + fShiftX + fZoomX * 155 * (float)(Math.Sin(2 * tmin + 1) * Math.Cos(3 * tmin)),
                y0 = panelCoordinateSystem.Height / 2 + fShiftY - 155 * fZoomY * (float)(Math.Sin(2 * tmin + 1) - Math.Sin(3 * tmin));
            for (t = tmin; t < tmax; t += 0.005)
            {
                x = panelCoordinateSystem.Width / 2 + fShiftX + fZoomX * 155 * (float)(Math.Sin(2 * t + 1) * Math.Cos(3 * t));
                y = panelCoordinateSystem.Height / 2 + fShiftY - 155 * fZoomY * (float)(Math.Sin(2 * t + 1) - Math.Sin(3 * t));
                e.Graphics.DrawLine(myPen, x, y, x0, y0);
                x0 = x;
                y0 = y;
            }
        }
        //Функция рисующая оси координатные
        private void paintAxises(PaintEventArgs e)
        {
            //Оси
            float fHeight = panelCoordinateSystem.Height;
            float fWidth = panelCoordinateSystem.Width;
            Font fontAxis = new Font("Arial", 16);
            SolidBrush myBrush = new SolidBrush(Color.GreenYellow);
            e.Graphics.DrawLine(penAxis, 0, fHeight/2 + fShiftY, fWidth, fHeight/2 + fShiftY);
            e.Graphics.DrawLine(penAxis, fWidth/2 + fShiftX, 0, fWidth/2 + fShiftX, fHeight);
            //Стрелка X
            e.Graphics.DrawLine(penAxis, fWidth, fHeight/2 + fShiftY, fWidth - 10, fHeight/2 + fShiftY - 5);
            e.Graphics.DrawLine(penAxis, fWidth, fHeight/2 + fShiftY, fWidth - 10, fHeight/2 + fShiftY + 5);
            e.Graphics.DrawString("X", fontAxis, myBrush, fWidth - 20, fHeight / 2 + fShiftY + 5);
            //Стрелка Y
            e.Graphics.DrawString("Y", fontAxis, myBrush, fWidth/2 + fShiftX + 10 , 5);
            e.Graphics.DrawLine(penAxis, fHeight/2 + fShiftX, 0, fWidth/2 + fShiftX - 5, 10);
            e.Graphics.DrawLine(penAxis, fHeight/2 + fShiftX, 0, fWidth/2 + fShiftX + 5, 10);
        }
        //Событие рисования на панели координатной системы
        private void panelCoordinateSystem_Paint(object sender, PaintEventArgs e)
        {
            if (bFirst)
            {
                fShiftX = 0; fShiftY = 0;
                bFirst = false;
            }
            paintAxises(e); //оси
            paintLines(e); // линии
            paintGraph(e); // график
        }
        //Событие нажатия на кнопки общего зума
        private void buttonZoom_Click(object sender, EventArgs e)
        {
            buttonZoomX_Click(sender, null);
            buttonZoomY_Click(sender, null);
        }
        //Событие нажатия на кнопки зума оси X
        private void buttonZoomX_Click(object sender, EventArgs e)
        {
            char key = Convert.ToChar(((Button)sender).Tag.ToString());
            switch(key)
            {
                case '+':
                    fZoomX += (float)0.1;
                    break;
                case '-':
                    if (fZoomX > 0.1)
                        fZoomX -= (float)0.1;
                    else MessageBox.Show("Достигнуто максимальное уменьшение по X");                    
                    break;
            }
            Refresh();
        }
        //Событие нажатия на кнопки зума оси Y
        private void buttonZoomY_Click(object sender, EventArgs e)
        {
            char key = Convert.ToChar(((Button)sender).Tag.ToString());
            switch (key)
            {
                case '+':
                    fZoomY += (float)0.1;
                    break;
                case '-':
                    if (fZoomY > 0.1)
                        fZoomY -= (float)0.1;
                    else MessageBox.Show("Достигнуто максимальное уменьшение по Y");
                    break;
            }
            Refresh();
        }
        //Событие нажатия на кнопку "построить"
        private void buttonPaint_Click(object sender, EventArgs e)
        {
            try
            {
                tmin = float.Parse(textBoxTmin.Text);
                tmax = float.Parse(textBoxTmax.Text);
            }
            catch
            {
                MessageBox.Show("ошибка");
            }
            if (tmin >= 0 && tmin <= Math.PI * 3 && tmax >= 0 && tmax <= Math.PI * 3 && tmin <= tmax)
            {
                
                textBoxCrossX.Clear();
                textBoxCrossY.Clear();
                textBoxMax.Clear();
                textBoxMin.Clear();
                Refresh();
                findParametrs();
            }
            else
            {
                tmin = 0; tmax = 0;
                MessageBox.Show("неверный интервал");
            }
        }
        //Событие перемещение бегунка трэкбара X
        private void trackBarMoveX_ValueChanged(object sender, EventArgs e)
        {
            fShiftX += (iValueX - trackBarMoveX.Value)* 15 * fZoomX;
            iValueX = trackBarMoveX.Value;
            Refresh();
        }
        //Событие перемещения бегунка трэкбара Y
        private void trackBarMoveY_ValueChanged(object sender, EventArgs e)
        {
            fShiftY += (iValueY - trackBarMoveY.Value) * 15 * fZoomY;
            iValueY = trackBarMoveY.Value;
            Refresh();
        }
        //Событие нажатия на кнопки в окнах ввода промежкутка t
        private void textBoxTmin_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar <= '9' && e.KeyChar >= '0') { }
            else
                if (e.KeyChar == ','&&!(((TextBox)sender).Text.Contains(",")) || e.KeyChar == (char)8) { }
                else e.KeyChar = (char)0;
        }
        //Событие изменения флага отображения сетки
        private void checkBoxNet_CheckedChanged(object sender, EventArgs e)
        {
            Refresh();
        }
        //Событие нажатия на кнопку "Выход"
        private void buttonExit_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}

 

Revise this Paste

Your Name: Code Language: