Advertisement
neongm

Untitled

Nov 10th, 2020
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.23 KB | None | 0 0
  1. #pragma once
  2. #include <math.h>
  3. #include <string>
  4. #include <vector>
  5. #include <msclr\marshal_cppstd.h>
  6. namespace laba418 {
  7.  
  8.     using namespace System;
  9.     using namespace System::ComponentModel;
  10.     using namespace System::Collections;
  11.     using namespace System::Windows::Forms;
  12.     using namespace System::Data;
  13.     using namespace System::Drawing;
  14.     int point1[4];
  15.     int point2[4];
  16.     int point3[4];
  17.     /// <summary>
  18.     /// Сводка для MyForm
  19.     /// </summary>
  20.     public ref class MyForm : public System::Windows::Forms::Form
  21.     {
  22.     public:
  23.         MyForm(void)
  24.         {
  25.             InitializeComponent();
  26.             //
  27.             //TODO: добавьте код конструктора
  28.             //
  29.         }
  30.  
  31.     protected:
  32.         /// <summary>
  33.         /// Освободить все используемые ресурсы.
  34.         /// </summary>
  35.         ~MyForm()
  36.         {
  37.             if (components)
  38.             {
  39.                 delete components;
  40.             }
  41.         }
  42.     private: System::Windows::Forms::Button^ button1;
  43.     private: System::Windows::Forms::PictureBox^ pictureBox1;
  44.     private: System::Windows::Forms::NumericUpDown^ numericUpDown1;
  45.     private: System::Windows::Forms::ListBox^ listBox1;
  46.     private: System::Windows::Forms::Label^ label1;
  47.     private: System::Windows::Forms::NumericUpDown^ numericUpDown2;
  48.     protected:
  49.  
  50.     private:
  51.         /// <summary>
  52.         /// Обязательная переменная конструктора.
  53.         /// </summary>
  54.         System::ComponentModel::Container ^components;
  55.  
  56. #pragma region Windows Form Designer generated code
  57.         /// <summary>
  58.         /// Требуемый метод для поддержки конструктора — не изменяйте
  59.         /// содержимое этого метода с помощью редактора кода.
  60.         /// </summary>
  61.         void InitializeComponent(void)
  62.         {
  63.             this->button1 = (gcnew System::Windows::Forms::Button());
  64.             this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
  65.             this->numericUpDown1 = (gcnew System::Windows::Forms::NumericUpDown());
  66.             this->listBox1 = (gcnew System::Windows::Forms::ListBox());
  67.             this->label1 = (gcnew System::Windows::Forms::Label());
  68.             this->numericUpDown2 = (gcnew System::Windows::Forms::NumericUpDown());
  69.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
  70.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown1))->BeginInit();
  71.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown2))->BeginInit();
  72.             this->SuspendLayout();
  73.             //
  74.             // button1
  75.             //
  76.             this->button1->Location = System::Drawing::Point(13, 8);
  77.             this->button1->Margin = System::Windows::Forms::Padding(4);
  78.             this->button1->Name = L"button1";
  79.             this->button1->Size = System::Drawing::Size(74, 30);
  80.             this->button1->TabIndex = 0;
  81.             this->button1->Text = L"draw";
  82.             this->button1->UseVisualStyleBackColor = true;
  83.             this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
  84.             //
  85.             // pictureBox1
  86.             //
  87.             this->pictureBox1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
  88.             this->pictureBox1->Location = System::Drawing::Point(13, 45);
  89.             this->pictureBox1->Margin = System::Windows::Forms::Padding(4);
  90.             this->pictureBox1->Name = L"pictureBox1";
  91.             this->pictureBox1->Size = System::Drawing::Size(256, 256);
  92.             this->pictureBox1->TabIndex = 1;
  93.             this->pictureBox1->TabStop = false;
  94.             this->pictureBox1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::pictureBox1_Paint);
  95.             //
  96.             // numericUpDown1
  97.             //
  98.             this->numericUpDown1->Font = (gcnew System::Drawing::Font(L"Segoe UI Light", 11.8F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  99.                 static_cast<System::Byte>(204)));
  100.             this->numericUpDown1->Location = System::Drawing::Point(95, 9);
  101.             this->numericUpDown1->Margin = System::Windows::Forms::Padding(4);
  102.             this->numericUpDown1->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 259, 0, 0, 0 });
  103.             this->numericUpDown1->Name = L"numericUpDown1";
  104.             this->numericUpDown1->Size = System::Drawing::Size(74, 28);
  105.             this->numericUpDown1->TabIndex = 2;
  106.             //
  107.             // listBox1
  108.             //
  109.             this->listBox1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
  110.             this->listBox1->FormattingEnabled = true;
  111.             this->listBox1->ItemHeight = 17;
  112.             this->listBox1->Location = System::Drawing::Point(277, 45);
  113.             this->listBox1->Margin = System::Windows::Forms::Padding(4);
  114.             this->listBox1->Name = L"listBox1";
  115.             this->listBox1->Size = System::Drawing::Size(256, 257);
  116.             this->listBox1->TabIndex = 3;
  117.             //
  118.             // label1
  119.             //
  120.             this->label1->AutoSize = true;
  121.             this->label1->Location = System::Drawing::Point(177, 13);
  122.             this->label1->Name = L"label1";
  123.             this->label1->Size = System::Drawing::Size(135, 19);
  124.             this->label1->TabIndex = 4;
  125.             this->label1->Text = L"- длинна стороны a ";
  126.             //
  127.             // numericUpDown2
  128.             //
  129.             this->numericUpDown2->Location = System::Drawing::Point(378, 11);
  130.             this->numericUpDown2->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 360, 0, 0, 0 });
  131.             this->numericUpDown2->Name = L"numericUpDown2";
  132.             this->numericUpDown2->Size = System::Drawing::Size(120, 25);
  133.             this->numericUpDown2->TabIndex = 5;
  134.             //
  135.             // MyForm
  136.             //
  137.             this->AutoScaleDimensions = System::Drawing::SizeF(7, 17);
  138.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  139.             this->ClientSize = System::Drawing::Size(550, 319);
  140.             this->Controls->Add(this->numericUpDown2);
  141.             this->Controls->Add(this->label1);
  142.             this->Controls->Add(this->listBox1);
  143.             this->Controls->Add(this->numericUpDown1);
  144.             this->Controls->Add(this->pictureBox1);
  145.             this->Controls->Add(this->button1);
  146.             this->Font = (gcnew System::Drawing::Font(L"Segoe UI Light", 10, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  147.                 static_cast<System::Byte>(204)));
  148.             this->Margin = System::Windows::Forms::Padding(4);
  149.             this->Name = L"MyForm";
  150.             this->Text = L"4.18";
  151.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
  152.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown1))->EndInit();
  153.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown2))->EndInit();
  154.             this->ResumeLayout(false);
  155.             this->PerformLayout();
  156.  
  157.         }
  158. #pragma endregion
  159.         void DebugHandler(std::string message) {
  160.             listBox1->Items->Insert(listBox1->Items->Count, cs(message));
  161.         }void DebugHandler(String^ message) {
  162.             listBox1->Items->Insert(listBox1->Items->Count, message);
  163.         }
  164.         template<typename T>
  165.         void DebugVector(std::vector<T> vec, std::string message) {
  166.             listBox1->Items->Insert(listBox1->Items->Count, cs(message + " ["));
  167.             for (size_t i = 0; i < vec.size(); i++) listBox1->Items->Insert(listBox1->Items->Count, cs("    " + s(vec.at(i))));
  168.             listBox1->Items->Insert(listBox1->Items->Count, cs("]"));
  169.         }
  170.         int decToInt(const System::Decimal& dec) {
  171.             return dec.ToInt32(dec); // работает, лол
  172.         }
  173.         // converts System::String to std::string
  174.         std::string s(String^ str) {
  175.             return msclr::interop::marshal_as<std::string>(str);
  176.         }std::string s(System::Decimal dec) {
  177.             return std::to_string(decToInt(dec));
  178.         }template<typename T>
  179.             std::string s(const T& value) {  // converts ints, floats and anything it can to std::string
  180.             return std::to_string(value);
  181.         }
  182.         // converts std::string to System::String^
  183.         System::String^ cs(std::string str) {
  184.             return gcnew String(str.c_str());
  185.         }
  186.  
  187.         void Rotate(int* array, const double& grad) {
  188.             int x1 = array[0];
  189.             int y1 = array[1];
  190.             int x2 = array[2];
  191.             int y2 = array[3];
  192.             array[0] = x1 * Cos(grad) + y1 * Sin(grad);
  193.             array[1] = x1 * Sin(grad) + y1 * Cos(grad);
  194.             array[2] = x2 * Cos(grad) + y2 * Sin(grad);
  195.             array[3] = x2 * Sin(grad) + y2 * Cos(grad);
  196.         }
  197.         void Transpose(int* array, const int& tX, const int& tY) {
  198.             array[0] += tX;
  199.             array[1] += tY;
  200.             array[2] += tX;
  201.             array[3] += tY;
  202.         }
  203.        
  204.         // преобразование градусов в радианы
  205.         float toRad(const float& grad) { return grad * (3.1415926535 / 180);}
  206.         // Sin для градусов, не радиан
  207.         double Sin(const double& grad) { return sin(grad * (3.1415926535 / 180)); }
  208.         double Cos(const double& grad) { return cos(grad * (3.1415926535 / 180)); }
  209.  
  210.     private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
  211.         double g = Convert::ToInt32(numericUpDown2->Value);
  212.         int a = Convert::ToInt32(numericUpDown1->Value);
  213.         DebugHandler("side a length:"+s(a));
  214.         int m = int(a / 2); //x для нижней вершины
  215.         int h = m * Sin(60)*2; //y для нижней вершины
  216.         DebugHandler("sin60 = " + s(Sin(60)));
  217.         int PictureBoxSize = 256;
  218.         int transposeY = PictureBoxSize/2-h/2;
  219.         DebugHandler("transposeY = " + s(transposeY));
  220.         int transposeX = PictureBoxSize/2-m;
  221.         DebugHandler("transposeX = " + s(transposeX));
  222.         //координаты расположены в порядке x1y1x2y2
  223.         point1[0] = 0;
  224.         point1[1] = 0;
  225.         point1[2] = a;
  226.         point1[3] = 0;
  227.         Rotate(point1, g);
  228.         Transpose(point1, transposeX, transposeY);
  229.         //Rotate(point1, g);
  230.         DebugHandler("line 1:  x1="+s(point1[0])+" y1="+s(point1[1])+"    x2="+s(point1[2]) + " y2=" + s(point1[3]));
  231.         point2[0] = a;
  232.         point2[1] = 0;
  233.         point2[2] = m;
  234.         point2[3] = h;
  235.         Rotate(point2, g);
  236.         Transpose(point2, transposeX, transposeY);
  237.         //Rotate(point2, g);
  238.         DebugHandler("line 2:  x1=" + s(point2[0]) + " y1=" + s(point2[1]) + "    x2=" + s(point2[2]) + " y2=" + s(point2[3]));
  239.         point3[0] = m;
  240.         point3[1] = h;
  241.         point3[2] = 0;
  242.         point3[3] = 0;
  243.         Rotate(point3, g);
  244.         Transpose(point3, transposeX, transposeY);
  245.         //Rotate(point3, g);
  246.         DebugHandler("line 3:  x1=" + s(point3[0]) + " y1=" + s(point3[1]) + "    x2=" + s(point3[2]) + " y2=" + s(point3[3]));
  247.        
  248.         pictureBox1->Refresh();
  249.     }
  250.     private: System::Void pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
  251.         e->Graphics->DrawLine(System::Drawing::Pens::Blue, point1[0], point1[1], point1[2], point1[3]);
  252.         e->Graphics->DrawLine(System::Drawing::Pens::Green, point2[0], point2[1], point2[2], point2[3]);
  253.         e->Graphics->DrawLine(System::Drawing::Pens::Red, point3[0], point3[1], point3[2], point3[3]);
  254.     }
  255.     };
  256. }
  257.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement