public partial class Form1 Form Double Phi Psi const int MAXX 800 cons

  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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
public partial class Form1 : Form
{
Double Phi, Psi;
const int MAXX = 800;//?
const int MAXY = 480;//?
int[] YMax = new int[MAXX];//?
int[] YMin = new int[MAXX];//?
Boolean flag = false;
public Form1()
{
InitializeComponent();
Psi = 3;
Phi = 350;
tPSI.Value = 3;
tPHI.Value = 350;
this.pictureBox1.Paint += new PaintEventHandler(this.picPaint);
}
public void picPaint(object sender, PaintEventArgs e)//?(2 флага одинаковых)
{
if(flag)
PlotSurface(-5, -5, 5, 5, -0.2, 0.3, 1000, 100, 20, 380, e.Graphics);
if (!flag)
PlotSurface(-5, -5, 5, 5, -0.2, 0.3, 1000, 100, 20, 380, e.Graphics);
}
public void PlotSurface(double x1, double y1, double x2, double y2, double fmin, double fmax, int n1, int n2, int Dx, int Dy, Graphics g)
{
Point[] CurLine = new Point[n1];//?
double phi = Phi * Math.PI / 180;
double psi = Psi * Math.PI / 180;
double sin_phi = Math.Sin(phi);
double sin_psi = Math.Sin(psi);
double cos_phi = Math.Cos(phi);
double cos_psi = Math.Cos(psi);
double[] e1 = new double[3] { cos_phi, sin_phi, 0 };//?
double[] e2 = new double[3] { sin_psi * sin_phi, -sin_psi * cos_phi, cos_psi };//?
double x, y;
double hx = (x2 - x1) / n1;//?
double hy = (y2 - y1) / n2;//?
double xmin = (e1[0] >= 0 ? x1 : x2) * e1[0] + (e1[1] >= 0 ? y1 : y2) * e1[1];//зачем они нам?
double xmax = (e1[0] >= 0 ? x2 : x1) * e1[0] + (e1[1] >= 0 ? y2 : y1) * e1[1];
double ymin = (e2[0] >= 0 ? x1 : x2) * e2[0] + (e2[1] >= 0 ? y1 : y2) * e2[1];
double ymax = (e2[0] >= 0 ? x2 : x1) * e2[0] + (e2[1] >= 0 ? y2 : y1) * e2[1];
int i, j;
if (e2[2] >= 0)//?
{
ymin += fmin * e2[2];
ymax += fmax * e2[2];
}
else
{
ymin += fmax * e2[2];
ymax += fmin * e2[2];
}
double ax = Dx - (MAXX - 40) * xmin / (xmax - xmin);//?
double bx = (MAXX - 40) / (xmax - xmin);//?
double ay = Dy - (MAXY - 80) * ymin / (ymax - ymin);//?
double by = -(MAXY - 80) / (ymax - ymin);//?
for (i = 0; i < MAXX; i++)//?
YMin[i] = YMax[i] = 0;
for (i = n2 - 1; i > -1; i--)//?
{
for (j = 0; j < n1; j++)
{
x = x1 + j * hx;
y = y1 + i * hy;
CurLine[j].X = (int)(ax + bx * (x * e1[0] + y * e1[1]));
CurLine[j].Y = (int)(ay + by * (x * e2[0] + y * e2[1] + f(x, y) * e2[2]));
}
for (j = 0; j < n1 - 1; j++)//?
DrawLine(CurLine[j], CurLine[j + 1], g);
///g.DrawLine(new Pen(Color.Black), CurLine[j], CurLine[j + 1]);
}
}
double f(double x, double y)//зачем?
{
double r = Math.Sin(x * x / 225 + y * y / 64) + 1;
return Math.Sqrt(r);
}
private void tPSI_Scroll(object sender, EventArgs e)
{
Psi = tPSI.Value;
flag = true;
pictureBox1.Invalidate();
}
private void tPHI_Scroll(object sender, EventArgs e)
{
Phi = tPHI.Value;
flag = true;
pictureBox1.Invalidate();
}
private void button1_Click_1(object sender, EventArgs e)
{
tPHI.Value = 320;
tPSI.Value = 3;
flag = false;
pictureBox1.Invalidate();
}
private void DrawLine(Point p1, Point p2, Graphics g)
{
Color UpColor = Color.Red;
Color DownColor = Color.Green;
int dx = Math.Abs(p2.X - p1.X);//шаг?
int dy = Math.Abs(p2.Y - p1.Y);
int sx = p2.X >= p1.X ? 1 : -1;//?
int sy = p2.Y >= p1.Y ? 1 : -1;
if (dy <= dx)//?
{
int d = -dx;
int d1 = dy << 1;//?
int d2 = (dy - dx) << 1;//?
for (int x = p1.X, y = p1.Y, i = 0; i <= dx; i++, x += sx)//?
{
if (YMin[x] == 0)//?
{
g.DrawRectangle(new Pen(UpColor), x, y, 1, 1);
YMin[x] = YMax[x] = y;
}
else if (y < YMin[x])//?
{
g.DrawRectangle(new Pen(UpColor), x, y, 1, 1);
YMin[x] = y;
}
else if (y > YMax[x])//?
{
g.DrawRectangle(new Pen(DownColor), x, y, 1, 1);
YMax[x] = y;
}
if (d > 0)//?
{
d += d2;
y += sy;
}
else d += d1;//?
}
}
else
{
int d = -dy;
int d1 = dx << 1;
int d2 = (dx - dy) << 1;
int m1 = YMin[p1.X];//?
int m2 = YMax[p1.X];//?
for (int x = p1.X, y = p1.Y, i = 0; i <= dy; i++, y += sy)//?
{
if (YMin[x] == 0)//что рисуем?
{
g.DrawRectangle(new Pen(UpColor), x, y, 1, 1);
YMin[x] = YMax[x] = y;
}
else if (y < m1)//?
{
g.DrawRectangle(new Pen(UpColor), x, y, 1, 1);
if (y < YMin[x])
YMin[x] = y;
}
else if (y > m2)//?
{
g.DrawRectangle(new Pen(DownColor), x, y, 1, 1);
if (y > YMax[x])
YMax[x] = y;
}
if (d > 0)//?
{
d += d2;
x += sx;
m1 = YMin[x]; m2 = YMax[x];
}
else d += d1;
}
}
}
}
}