Аффинные преобразования в пространстве. Простейшие аффинные преобразования в пространстве: перенос, сдвиг, поворот, масштабирование, страница 2

rez[i, j] += matr[i, k] * points[k, j];

}

for (i = 0; i < n_matr; i++)

for (j = 0; j < vertex_count; j++) points[i, j] = rez[i, j];

return rez;

}

//графическое построение

private void pnlXOZ_Paint(object sender, PaintEventArgs e)

{

Pen OXY = new Pen(Color.Blue, 2); //перо оси XOY

Pen setka = new Pen(Color.Gray, 1); //перо масштабной сетки

Pen figur = new Pen(Color.Red, 3); //перо для рисования фигуры

Pen figur1 = new Pen(Color.Blue, 3);

Graphics g = e.Graphics;

Font txt = new Font("Arial", 14, FontStyle.Bold);

int count = 0;

float cx, cy;  //текущие точки плоскости XOY

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

g.FillRectangle(Brushes.White, 0, 0, pnlXOZ.Size.Width, pnlXOZ.Size.Height);

sizeX = int.Parse(mashtab_ox.Value.ToString());

sizeY = int.Parse(mashtab_oz.Value.ToString());

stepX = 1 / sizeX;

stepY = 1 / sizeY;

//рисование масштабной сетки по x

for (XY.X = centerXOZ.X, count = 0; XY.X < pnlXOZ.Size.Width; XY.X += sizeX, count--)

{

g.DrawLine(setka, XY.X, 0, XY.X, pnlXOZ.Size.Height);

g.DrawString(count.ToString(), txt, Brushes.Black, XY.X - txt.Size, centerXOZ.Y);

}

for (XY.X = centerXOZ.X, count = 0; XY.X > 0; XY.X -= sizeX, count++)

{

g.DrawLine(setka, XY.X, 0, XY.X, pnlXOZ.Size.Height);

if (count != 0)

g.DrawString(count.ToString(), txt, Brushes.Black, XY.X - 1.5f * txt.Size, centerXOZ.Y);

}

//по y

for (XY.Y = centerXOZ.Y, count = 0; XY.Y > 0; XY.Y -= sizeY, count++)

{

g.DrawLine(setka, 0, XY.Y, pnlXOZ.Size.Width, XY.Y);

g.DrawString(count.ToString(), txt, Brushes.Black, centerXOZ.X - txt.Size, XY.Y);

}

for (XY.Y = centerXOZ.Y, count = 0; XY.Y < pnlXOZ.Size.Height; XY.Y += sizeY, count--)

{

g.DrawLine(setka, 0, XY.Y, pnlXOZ.Size.Width, XY.Y);

if (count != 0)

g.DrawString(count.ToString(), txt, Brushes.Black, centerXOZ.X - 1.5f * txt.Size, XY.Y);

}

//рисование координатных осей

g.DrawLine(OXY, 0, centerXOZ.Y, pnlXOZ.Size.Width, centerXOZ.Y);

g.DrawLine(OXY, centerXOZ.X, 0, centerXOZ.X, pnlXOZ.Size.Height);

g.DrawString("0", txt, Brushes.Black, centerXOZ.X - txt.Size, centerXOZ.Y);

cx = local_x;

cy = local_z;

relX = cx / stepX;

relY = cy / stepY;

XY.X = centerXOZ.X - relX;

XY.Y = centerXOZ.Y - relY;

g.FillEllipse(Brushes.Green, XY.X - 10, XY.Y - 10, 20, 20);

for (int i = 0; i < 8; i++) //преобразование точек плоскости в экранные

{

cx = old_points[0, i];

cy = old_points[2, i];

relX = cx / stepX;

relY = cy / stepY;

XY.X = centerXOZ.X - relX;

XY.Y = centerXOZ.Y - relY;

old_scr_points[i].X = XY.X;

old_scr_points[i].Y = XY.Y;

}

g.DrawLine(figur1, old_scr_points[0], old_scr_points[3]); //рисование фигуры

g.DrawLine(figur1, old_scr_points[0], old_scr_points[1]);

g.DrawLine(figur1, old_scr_points[1], old_scr_points[2]);

g.DrawLine(figur1, old_scr_points[2], old_scr_points[3]);

g.DrawLine(figur1, old_scr_points[0], old_scr_points[4]);

g.DrawLine(figur1, old_scr_points[1], old_scr_points[5]);

g.DrawLine(figur1, old_scr_points[2], old_scr_points[6]);

g.DrawLine(figur1, old_scr_points[3], old_scr_points[7]);

g.DrawLine(figur1, old_scr_points[4], old_scr_points[5]);

g.DrawLine(figur1, old_scr_points[5], old_scr_points[6]);

g.DrawLine(figur1, old_scr_points[4], old_scr_points[7]);

g.DrawLine(figur1, old_scr_points[7], old_scr_points[6]);

for (int i = 0; i < 8; i++) //преобразование точек плоскости в экранные

{

cx = points[0, i];

cy = points[2, i];

relX = cx / stepX;

relY = cy / stepY;

XY.X =  centerXOZ.X-relX;

XY.Y = centerXOZ.Y - relY;

scr_points[i].X = XY.X;

scr_points[i].Y = XY.Y;

}

g.DrawLine(figur, scr_points[0], scr_points[3]); //рисование фигуры

g.DrawLine(figur, scr_points[0], scr_points[1]);

g.DrawLine(figur, scr_points[1], scr_points[2]);