Листинг 42.1. Код для рисования изображения.
//Концы числового интервала области задания поверхности:
private: static const float x_min = -1.5;
private: static const float x_max = 1.5;
private: static const float y_min = -1.5;
private: static const float y_max = 1.5;
private:
System::Void pictureBox1_Paint(System::Object^ sender,
System::Windows::Forms::PaintEventArgs^ e)
{
//Масштабируем объекты класса Graphics на pictureBox1.
//Коэффициенты масштабирования:
float M_1 = 2 * (x_max - x_min);
float M_2 = 2 * (y_max - y_min);
e->Graphics->ScaleTransform(
Convert::ToSingle(pictureBox1->Width / M_1),
Convert::ToSingle(pictureBox1->Height / M_2));
float M_3 = 2 * (-x_min); float M_4 = 2 * (-y_min);
e->Graphics->TranslateTransform(M_3, M_4,
MatrixOrder::Prepend);
//Задавая M_1, M_2, M_3, M_4 другие значения,
//мы будем смещать линии уровня на pictureBox1.
//Объявляем индексы элементов всех массивов:
int i, j, k;
//Задаем границы индексов массива myArrayVC(i, j):
int N_x = 20001; int N_y = 2;
//Объявляем массив myArrayVC[i, j] пер-х типа float,
//когда i = 0,1,2,3,...,(N_x - 1);
// j = 0,1,2,3,...,(N_y - 1):
array<float,2>^ myArrayVC =
gcnew array<float,2>(N_x, N_y);
//Для считывания из файла
//по адресу D:\\MyDocs\\MyTest_LevelCurves.txt
//координат изображения в массив myArrayVC(20001, 2)
//создаем объект sr класса StreamReader:
String^ path = "D:\\MyDocs\\MyTest_LevelCurves.txt";
StreamReader^ sr = gcnew StreamReader(path);
//Считываем из файла MyTest_LevelCurves.txt
//координаты изображения в массив myArrayVC(20001, 2)
//при помощи метода ReadLine:
for (i = 0; i <= N_x - 1; i++)
for (j = 0; j <= N_y - 1; j++)
myArrayVC[i, j] = Convert::ToSingle(sr->ReadLine());
sr->Close();
//Рисуем изображение по координатам из массива.