Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <math.h>
- #include <string>
- #include <vector>
- #include <msclr\marshal_cppstd.h>
- namespace laba418 {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- int point1[4];
- int point2[4];
- int point3[4];
- /// <summary>
- /// Сводка для MyForm
- /// </summary>
- public ref class MyForm : public System::Windows::Forms::Form
- {
- public:
- MyForm(void)
- {
- InitializeComponent();
- //
- //TODO: добавьте код конструктора
- //
- }
- protected:
- /// <summary>
- /// Освободить все используемые ресурсы.
- /// </summary>
- ~MyForm()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::Button^ button1;
- private: System::Windows::Forms::PictureBox^ pictureBox1;
- private: System::Windows::Forms::NumericUpDown^ numericUpDown1;
- private: System::Windows::Forms::ListBox^ listBox1;
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::NumericUpDown^ numericUpDown2;
- protected:
- private:
- /// <summary>
- /// Обязательная переменная конструктора.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Требуемый метод для поддержки конструктора — не изменяйте
- /// содержимое этого метода с помощью редактора кода.
- /// </summary>
- void InitializeComponent(void)
- {
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
- this->numericUpDown1 = (gcnew System::Windows::Forms::NumericUpDown());
- this->listBox1 = (gcnew System::Windows::Forms::ListBox());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->numericUpDown2 = (gcnew System::Windows::Forms::NumericUpDown());
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown1))->BeginInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown2))->BeginInit();
- this->SuspendLayout();
- //
- // button1
- //
- this->button1->Location = System::Drawing::Point(13, 8);
- this->button1->Margin = System::Windows::Forms::Padding(4);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(74, 30);
- this->button1->TabIndex = 0;
- this->button1->Text = L"draw";
- this->button1->UseVisualStyleBackColor = true;
- this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
- //
- // pictureBox1
- //
- this->pictureBox1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
- this->pictureBox1->Location = System::Drawing::Point(13, 45);
- this->pictureBox1->Margin = System::Windows::Forms::Padding(4);
- this->pictureBox1->Name = L"pictureBox1";
- this->pictureBox1->Size = System::Drawing::Size(256, 256);
- this->pictureBox1->TabIndex = 1;
- this->pictureBox1->TabStop = false;
- this->pictureBox1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::pictureBox1_Paint);
- //
- // numericUpDown1
- //
- this->numericUpDown1->Font = (gcnew System::Drawing::Font(L"Segoe UI Light", 11.8F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->numericUpDown1->Location = System::Drawing::Point(95, 9);
- this->numericUpDown1->Margin = System::Windows::Forms::Padding(4);
- this->numericUpDown1->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 259, 0, 0, 0 });
- this->numericUpDown1->Name = L"numericUpDown1";
- this->numericUpDown1->Size = System::Drawing::Size(74, 28);
- this->numericUpDown1->TabIndex = 2;
- //
- // listBox1
- //
- this->listBox1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
- this->listBox1->FormattingEnabled = true;
- this->listBox1->ItemHeight = 17;
- this->listBox1->Location = System::Drawing::Point(277, 45);
- this->listBox1->Margin = System::Windows::Forms::Padding(4);
- this->listBox1->Name = L"listBox1";
- this->listBox1->Size = System::Drawing::Size(256, 257);
- this->listBox1->TabIndex = 3;
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Location = System::Drawing::Point(177, 13);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(135, 19);
- this->label1->TabIndex = 4;
- this->label1->Text = L"- длинна стороны a ";
- //
- // numericUpDown2
- //
- this->numericUpDown2->Location = System::Drawing::Point(378, 11);
- this->numericUpDown2->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 360, 0, 0, 0 });
- this->numericUpDown2->Name = L"numericUpDown2";
- this->numericUpDown2->Size = System::Drawing::Size(120, 25);
- this->numericUpDown2->TabIndex = 5;
- //
- // MyForm
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(7, 17);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(550, 319);
- this->Controls->Add(this->numericUpDown2);
- this->Controls->Add(this->label1);
- this->Controls->Add(this->listBox1);
- this->Controls->Add(this->numericUpDown1);
- this->Controls->Add(this->pictureBox1);
- this->Controls->Add(this->button1);
- this->Font = (gcnew System::Drawing::Font(L"Segoe UI Light", 10, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->Margin = System::Windows::Forms::Padding(4);
- this->Name = L"MyForm";
- this->Text = L"4.18";
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown1))->EndInit();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown2))->EndInit();
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- void DebugHandler(std::string message) {
- listBox1->Items->Insert(listBox1->Items->Count, cs(message));
- }void DebugHandler(String^ message) {
- listBox1->Items->Insert(listBox1->Items->Count, message);
- }
- template<typename T>
- void DebugVector(std::vector<T> vec, std::string message) {
- listBox1->Items->Insert(listBox1->Items->Count, cs(message + " ["));
- for (size_t i = 0; i < vec.size(); i++) listBox1->Items->Insert(listBox1->Items->Count, cs(" " + s(vec.at(i))));
- listBox1->Items->Insert(listBox1->Items->Count, cs("]"));
- }
- int decToInt(const System::Decimal& dec) {
- return dec.ToInt32(dec); // работает, лол
- }
- // converts System::String to std::string
- std::string s(String^ str) {
- return msclr::interop::marshal_as<std::string>(str);
- }std::string s(System::Decimal dec) {
- return std::to_string(decToInt(dec));
- }template<typename T>
- std::string s(const T& value) { // converts ints, floats and anything it can to std::string
- return std::to_string(value);
- }
- // converts std::string to System::String^
- System::String^ cs(std::string str) {
- return gcnew String(str.c_str());
- }
- void Rotate(int* array, const double& grad) {
- int x1 = array[0];
- int y1 = array[1];
- int x2 = array[2];
- int y2 = array[3];
- array[0] = x1 * Cos(grad) + y1 * Sin(grad);
- array[1] = x1 * Sin(grad) + y1 * Cos(grad);
- array[2] = x2 * Cos(grad) + y2 * Sin(grad);
- array[3] = x2 * Sin(grad) + y2 * Cos(grad);
- }
- void Transpose(int* array, const int& tX, const int& tY) {
- array[0] += tX;
- array[1] += tY;
- array[2] += tX;
- array[3] += tY;
- }
- // преобразование градусов в радианы
- float toRad(const float& grad) { return grad * (3.1415926535 / 180);}
- // Sin для градусов, не радиан
- double Sin(const double& grad) { return sin(grad * (3.1415926535 / 180)); }
- double Cos(const double& grad) { return cos(grad * (3.1415926535 / 180)); }
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
- double g = Convert::ToInt32(numericUpDown2->Value);
- int a = Convert::ToInt32(numericUpDown1->Value);
- DebugHandler("side a length:"+s(a));
- int m = int(a / 2); //x для нижней вершины
- int h = m * Sin(60)*2; //y для нижней вершины
- DebugHandler("sin60 = " + s(Sin(60)));
- int PictureBoxSize = 256;
- int transposeY = PictureBoxSize/2-h/2;
- DebugHandler("transposeY = " + s(transposeY));
- int transposeX = PictureBoxSize/2-m;
- DebugHandler("transposeX = " + s(transposeX));
- //координаты расположены в порядке x1y1x2y2
- point1[0] = 0;
- point1[1] = 0;
- point1[2] = a;
- point1[3] = 0;
- Rotate(point1, g);
- Transpose(point1, transposeX, transposeY);
- //Rotate(point1, g);
- DebugHandler("line 1: x1="+s(point1[0])+" y1="+s(point1[1])+" x2="+s(point1[2]) + " y2=" + s(point1[3]));
- point2[0] = a;
- point2[1] = 0;
- point2[2] = m;
- point2[3] = h;
- Rotate(point2, g);
- Transpose(point2, transposeX, transposeY);
- //Rotate(point2, g);
- DebugHandler("line 2: x1=" + s(point2[0]) + " y1=" + s(point2[1]) + " x2=" + s(point2[2]) + " y2=" + s(point2[3]));
- point3[0] = m;
- point3[1] = h;
- point3[2] = 0;
- point3[3] = 0;
- Rotate(point3, g);
- Transpose(point3, transposeX, transposeY);
- //Rotate(point3, g);
- DebugHandler("line 3: x1=" + s(point3[0]) + " y1=" + s(point3[1]) + " x2=" + s(point3[2]) + " y2=" + s(point3[3]));
- pictureBox1->Refresh();
- }
- private: System::Void pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
- e->Graphics->DrawLine(System::Drawing::Pens::Blue, point1[0], point1[1], point1[2], point1[3]);
- e->Graphics->DrawLine(System::Drawing::Pens::Green, point2[0], point2[1], point2[2], point2[3]);
- e->Graphics->DrawLine(System::Drawing::Pens::Red, point3[0], point3[1], point3[2], point3[3]);
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement