czwartek, 13 lipca 2017

Drawing trigonometric transformations (Visual C++)




struct x_y
{
int x_panel;
int y_panel;
double xr_width;
double yr_height;
};
double a[3];
double b[3];

float value_sin_1(double a1,double a2, double a3,double a4)
{
float value;
value=a1+a3*sin(-1.0*(a2-a3)/a3*a4);
return value;
}
float value_cos_1(double a1, double a2, double a3, double a4)
{
float value;
value=a1+a3*cos(-1.0*(a2-a3)/a3*a4);
return value;
}
float value_sin_2(double a1, double a2, double a3, double a4)
{
float value;
value=a1-a3*sin(-1.0*(a2-a3)/a3*a4);
return value;
}
float value_cos_2(double a1,double a2, double a3, double a4)
{
float value;
value=a1-a3*cos(-1.0*(a2-a3)/a3*a4);
return value;
}

float value_sin_3(double a1, double a2, double a3, double a4)
{
float value;
value=a1+(a2-a3)*sin(1.0*a4);
return value;
}
float value_cos_3(double a1, double a2, double a3, double a4)
{
float value;
value=a1+(a2-a3)*cos(1.0*a4);
return value;
}

#pragma endregion
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
Graphics^ draw1=panel1->CreateGraphics();
struct x_y date;
date.x_panel=panel1->Width/2;
date.y_panel=panel1->Height/2;
date.xr_width=1.*panel1->Width/2.;
date.yr_height=1.*panel1->Height/4.;
double pi=3.14159265359;
double max_value=3.0*pi;
double step;
Random^ random_value=gcnew Random();
Pen^ draw_pen;
System::Drawing::Color my_color;
for(step=0.0;step<max_value;step+=0.01)
{
a[0]=value_cos_3(date.x_panel,date.xr_width,date.yr_height,step);
b[0]=value_sin_3(date.x_panel,date.xr_width,date.yr_height,step);
a[1]=value_cos_1(a[0],date.xr_width,date.yr_height,step);
b[1]=value_sin_1(b[0],date.xr_width,date.yr_height,step);
a[2]=value_cos_2(a[1],date.xr_width,date.yr_height,step);
b[2]=value_sin_2(b[1],date.xr_width,date.yr_height,step);
my_color=System::Drawing::Color::FromArgb(random_value->Next(255),
random_value->Next(255),random_value->Next(255));
draw_pen=gcnew Pen(my_color);
draw1->DrawLine(draw_pen,int(a[1]),int(b[1]),int(a[2]),int(b[2]));
}
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
};
}


Brak komentarzy:

Prześlij komentarz