Работа вам нужна срочно. Не волнуйтесь, уложимся!
Заполните, пожалуйста, данные для автора:
- 22423 авторов готовы помочь тебе.
- 2402 онлайн
Вычерчиваются графики функций:
Астроида:
Для астроиды b=1,3 (вычерчивается синим цветом). Масштабирование выполняется с учетом размеров компонента Image1, в котором выполняется рисование. Для заданного промежутка изменения аргумента x находится промежуток изменения функции (y).
Файл Form1.h
#pragma once
namespace lab3 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
///
/// Summary for Form1
///
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
///
/// Clean up any resources being used.
///
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private:
///
/// Required designer variable.
///
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
void InitializeComponent(void)
{
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
(cli::safe_cast
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Location = System::Drawing::Point(12, 12);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(484, 367);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
this->pictureBox1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::pictureBox1_Paint);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(522, 391);
this->Controls->Add(this->pictureBox1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
this->MaximizeBox = false;
this->Name = L"Form1";
this->Text = L"Графики y=f(x)";
(cli::safe_cast
this->ResumeLayout(false);
}
#pragma endregion
private:
int l, b, h, w;
private: System::Void pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
h = pictureBox1->Height; // Ширина
w = pictureBox1->Width; // Высота
// Osi
e->Graphics->DrawLine(Pens::Black,0,h/2,w,h/2);
e->Graphics->DrawLine(Pens::Black,w/2,0,w/2,h);
// Strelki
e->Graphics->DrawLine(Pens::Black,w-25,h/2+8,w,h/2);
e->Graphics->DrawLine(Pens::Black,w-25,h/2-8,w,h/2);
e->Graphics->DrawLine(Pens::Black,w/2-8,25,w/2,0);
e->Graphics->DrawLine(Pens::Black,w/2+8,25,w/2,0);
// Podpisi
e->Graphics->DrawString("X",this->Font,Brushes::Black,w-15,h/2-25);
e->Graphics->DrawString("Y",this->Font,Brushes::Black,w/2-25,5);
double x1, x2, y1, y2, x, y, mx, my, x0, y0, dx,dt;
x1 = -5; // from
x2 = 5; // to
dx = 0.001; // step
y1 = 1/(3*(-5)*(-5)+2*(-5)+1);
y2 = 1/(3*5*5+2*5+1);
x = x1;
while(x <= x2)
{
y = 1/(3*x*x+2*x+1);
if (y < y1) y1 = y;
if (y > y2) y2 = y;
x+=dx;
}
my = 0.5*h/(y2-y1); // mashtab po osi y
mx = w/(x2-x1); // mashtab po osi x
x = x1;
y1=1/(3*x1*x1+2*x1+1);
x+=dx;
// График
while(x <= x2)
{
y = 1/(3*x*x+2*x+1);
e->Graphics->DrawLine(Pens::Black,(int)(x1*mx+w/2),(int)(h/2-y1*my),(int)(x*mx+w/2),(int)(h/2-y*my));
x1=x;
y1=y;
x+=dx;
}
x1 = -1.3; // from
x2 = 1.3; // to
dt = 0.001; // step
y1 = -1.3;
y2 = 1.3;
my = h/(y2-y1); // mashtab po osi y
mx = w/(x2-x1); // mashtab po osi x
double t = 0;
// График
x1=Math::Cos(t)*Math::Cos(t)*Math::Cos(t)*1.3;
y1=Math::Sin(t)*Math::Sin(t)*Math::Sin(t)*1.3;
t+=dt;
while(t <= 2*3.14)
{
x=Math::Cos(t)*Math::Cos(t)*Math::Cos(t)*1.3;
y=Math::Sin(t)*Math::Sin(t)*Math::Sin(t)*1.3;
e->Graphics->DrawLine(Pens::Red,(int)(x1*mx+w/2),(int)(h/2-y1*my),(int)(x*mx+w/2),(int)(h/2-y*my));
t+=dt;
x1=x;
y1=y;
}
}
};
}
Вычерчивается поверхность
Файл реализации Form1.h
#pragma once
namespace lab3b {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
///
/// Summary for Form1
///
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
///
/// Clean up any resources being used.
///
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private:
///
/// Required designer variable.
///
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
void InitializeComponent(void)
{
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
(cli::safe_cast
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Location = System::Drawing::Point(12, 12);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(401, 333);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
this->pictureBox1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::pictureBox1_Paint);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(458, 357);
this->Controls->Add(this->pictureBox1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
this->MaximizeBox = false;
this->Name = L"Form1";
this->Text = L"Поверхность z=f(x,y)";
(cli::safe_cast
this->ResumeLayout(false);
}
#pragma endregion
private:
static double x0=4,Y0=-0.5,z0=3,alf=4.31,bet=4.92,A=-6.5,a=-6.5;
static double Xmin=-1.5,Xmax=1.5,Ymin=-1.5,Ymax=1.5;
static int Width=200,Height=200;
static double h=0.1,h0=0.25;
static array
//------------------------------------------------------------------------------
//*********** void IJ(double x, double y, double z, array
private: void IJ(double x, double y, double z,array
{
double Xn,Yn,Zn;
//Осуществляем перенос системы координат в т.(x0,Y0,z0)
Xn=(x-x0)*Math::Cos(alf)-(y-Y0)*Math::Sin(alf);
Yn=((x-x0)*Math::Sin(alf)+(y-Y0)*Math::Cos(alf))*Math::Cos(bet)-(z-z0)*Math::Sin(bet);
Zn=((x-x0)*Math::Sin(alf)+(y-Y0)*Math::Cos(alf))*Math::Sin(bet)+(z-z0)*Math::Cos(bet);
//Делаем проекцию на плоскость
Xn/=Zn/A+1;
Yn/=Zn/a+1;
//Масштабируем оси x и y
ar[0]=Width*(Xn-Xmin)/(Xmax-Xmin);
ar[1]=Height*(Yn-Ymax)/(Ymin-Ymax);
}
//******* void IJ(double x, double y, double z, array
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//****** double F1(double x1,double y1) *****************************
private: double F1(double x1,double y1)
{
return 1/((x1+y1)*(x1+y1));
}
//***** double F1(double x1,double y1) *****************************
//------------------------------------------------------------------------------
//Рисование поверхности
private: System::Void pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
int i3,j3;
int i1,j1,i2,j2;
array
array
a1=gcnew array
a2=gcnew array
IJ(0,0,0,a1);
//Рисуем и подписываем ось x
IJ(4,0,0,a2);
e->Graphics->DrawLine(Pens::Red,a1[0],a1[1],a2[0],a2[1]);
e->Graphics->DrawString("X",this->Font,Brushes::Red,a2[0]+3,a2[1]);
//Рисуем и подписываем ось y
IJ(0,4,0,a2);
e->Graphics->DrawLine(Pens::Red,a1[0],a1[1],a2[0],a2[1]);
e->Graphics->DrawString("Y",this->Font,Brushes::Red,a2[0]+3,a2[1]);
//Рисуем и подписываем ось z
IJ(0,0,4.3,a2);
e->Graphics->DrawLine(Pens::Red,a1[0],a1[1],a2[0],a2[1]);
e->Graphics->DrawString("Z",this->Font,Brushes::Red,a2[0]+3,a2[1]-3);
for(j3=0;j3<25;j3++)
{
for(i3=0;i3<30;i3++)
{
IJ(h0+h*i3,h0+h*j3,F1(h0+h*i3,h0+h*j3),a1);
ob[0].X=a1[0];
ob[0].Y=a1[1];
IJ(h0+h*i3,h0+h*(j3+1),F1(h0+h*i3,h0+h*(j3+1)),a1);
ob[1].X=a1[0];
ob[1].Y=a1[1];
IJ(h0+h*(i3+1),h0+h*(j3+1),F1(h0+h*(i3+1),h0+h*(j3+1)),a1);
ob[2].X=a1[0];
ob[2].Y=a1[1];
IJ(h0+h*(i3+1),h0+h*j3,F1(h0+h*(i3+1),h0+h*j3),a1);
ob[3].X=a1[0];
ob[3].Y=a1[1];
e->Graphics->DrawPolygon(Pens::Blue,ob);
}
}
}
};
}