1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TaySystem
{
public partial class MyForm : Form
{
float xScale, yScale, //множители по осям
height, width; //размеры координатной сетки
float xZeroOffcet, yZeroOffcet; //смещение точки (0,0) от левого угла формы
Cell myCell; //звено
Graphics draw;
Pen pen;
List<PointF> points; //список точек для отрисовки звена
public MyForm()
{
InitializeComponent();
draw = this.CreateGraphics();
myCell = new Cell();
height = 400; width = 400;
xZeroOffcet = 0; yZeroOffcet = 0;
pen = new Pen(Color.Black, 1);
points = new List<PointF>();
}
/// <summary>
/// Генерирует координатную сетку
/// </summary>
/// <param name="xMinBound"></param>
/// <param name="yMinBound"></param>
/// <param name="xMaxBound"></param>
/// <param name="yMaxBound"></param>
void GenerateWave(int xMinBound, int yMinBound, int xMaxBound, int yMaxBound)
{
this.Refresh();
int swap = yMinBound;
yMinBound = yMaxBound * (-1); //меняем местами границы по У, т.к. у окна ось У напривлена вниз
yMaxBound = swap * (-1);
xScale = width / (xMaxBound - xMinBound); // расчет множителей по Х и У квадратики
yScale = height / (yMaxBound - yMinBound);
pen.Color = Color.Black;
pen.Width = 1;
for (int i = 0; xMinBound < xMaxBound + 1; i++, xMinBound ++) //вертикальные линии
{
if (xMinBound == 0) //нулевая ось
{
xZeroOffcet = i * xScale;// смещение оси х // расстояние от края формы до нулевой оси
pen.Width = 2;
}
draw.DrawLine(pen, i * xScale, 0, i * xScale, height);
pen.Width = 1;
}
for (int i = 0; yMinBound < yMaxBound + 1; i++, yMinBound ++) //горизонтальные линии
{
if (yMinBound == 0) //нулевая ось
{
yZeroOffcet = i * yScale;
pen.Width = 2;
}
draw.DrawLine(pen, 0, i * yScale, width, i * yScale);
pen.Width = 1;
}
}
private void updateButton_Click(object sender, EventArgs e)// звено, нажали кнопку
{
//задаем параметры звена
myCell.T1 = (float)t1NumericUpDown.Value;
myCell.T2 = (float)t2NumericUpDown.Value;
myCell.K = (float)kNumericUpDown.Value;
myCell.T = (float)offcetNumericUpDown.Value;
//генерируем новую координатную сетку
GenerateWave((int)XminUpDown.Value,
(int)YminUpDown.Value,
(int)XmaxUpDown.Value,
(int)YmaxUpDown.Value);
if(radioButton1.Checked) //кривая переходного процесса
points = myCell.CalculateFunction2(); //получаем точки
if (radioButton2.Checked) //афчх
{
points = myCell.CalculateFunction1((float)XmaxUpDown.Value);//получаем точки
}
if (points.Count == 0) { MessageBox.Show("Не инерционное звено!"); return; }
for (int i = 0; i < points.Count-1; i++) //строим кривую
{
pen.Color = Color.Blue;
pen.Width = 2;
draw.DrawLine(pen, points[i].X * xScale + xZeroOffcet,
points[i].Y * yScale * (-1) + yZeroOffcet,
points[i + 1].X * xScale + xZeroOffcet,
points[i + 1].Y * yScale * (-1) + yZeroOffcet
);
draw.DrawLine(pen, points[0].X, points[0].Y, points[0].X, points[0].Y);
}
points.Clear();
}
private void MyForm_Activated(object sender, EventArgs e) //это чтобы координатная сетка сгенерировалась сразу после запуска
{
GenerateWave((int)XminUpDown.Value,
(int)YminUpDown.Value,
(int)XmaxUpDown.Value,
(int)YmaxUpDown.Value);
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
XminUpDown.Value = -5;
YminUpDown.Value = -5; //если меняем, что рисовать, то меняем и границы сетки
XmaxUpDown.Value = 5;
YmaxUpDown.Value = 5;
GenerateWave((int)XminUpDown.Value, //заного генерируем сетку
(int)YminUpDown.Value,
(int)XmaxUpDown.Value,
(int)YmaxUpDown.Value);
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
XminUpDown.Value = -1;
YminUpDown.Value = -1;
XmaxUpDown.Value = 20;
YmaxUpDown.Value = 5;
GenerateWave((int)XminUpDown.Value,
(int)YminUpDown.Value,
(int)XmaxUpDown.Value,
(int)YmaxUpDown.Value);
}
}
} |