Вот есть код для C++ Builder 12, который создает и рисует окружности и так же проводит…
- User
Вот есть код для C++ Builder 12, который создает и рисует окружности и так же проводит их триангуляцию. Сделай так, чтобы все создаваемые треугольники всегда были равнобедренными: Unit1.h - //--------------------------------------------------------------------------- #ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include <Graphics.hpp> #include <ExtCtrls.hpp> #include <System.SysUtils.hpp> #include <System.Classes.hpp> #include <Vcl.Graphics.hpp> #include <Vcl.Controls.hpp> #include <Vcl.Forms.hpp> #include <Vcl.Dialogs.hpp> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TButton *Button1; TPaintBox *PaintBox1; TButton *Button2; TButton *Button3; // Кнопка для заполнения окружности TEdit *Edit1; void __fastcall Button1Click(TObject *Sender); void __fastcall Button2Click(TObject *Sender); void __fastcall Button3Click(TObject *Sender); // Изменен обработчик для заполнения
private:
codeTPoint LastCircleCenter; // Центральная точка последней окружности int LastCircleRadius; // Радиус последней окружности void DrawTriangulation();public: // User declarations __fastcall TForm1(TComponent* Owner); };
struct TPoint_2D { double x, y; int number; };
struct TPoint2D { TPoint_2D Vertex; }; std::vector Points; class CalculationNormal { public: double dx, dy, length, direction; void Calculation (double x1, double x2, double y1, double y2, double &normal_x, double &normal_y); }; std::vector<std::vector> Layers; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif Unit1.cpp - //--------------------------------------------------------------------------- #include <vcl.h> #include <windows.h> #include // Для std::rand() и std::srand() #include // Для std::time() #include // Для использования cos и sin #include // Для использования std::vector #pragma hdrstop
#include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1;
void CalculationNormal::Calculation(double x1, double x2, double y1, double y2, double &normal_x, double &normal_y) { dx = x2 - x1; dy = y2 - y1; length = sqrt(dx * dx + dy * dy); normal_x = -dy / length; normal_y = dx / length; direction = (x1 + x2) / 2 * normal_x + (y1 + y2) / 2 * normal_y; if (direction < 0) { normal_x = -normal_x; normal_y = -normal_y; } } //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { std::srand(static_cast(std::time(0))); // Призыв генератора случайных чисел LastCircleRadius = 0; // Изначально радиус не задан } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { // Получаем размеры PaintBox1 int width = PaintBox1->Width; int height = PaintBox1->Height;
- Assistant
- User
Код не заполняет центр окружностей, а так же границы окружности, образуя такой бублик с полостью внутри
- Assistant
- User
Код не заполняет центр окружностей треугольниками!, а так же границы окружности не заполняет прямыми между вершинами, касающимися границ
- Assistant
- User
[bcc32c Error] Unit1.cpp(210): too few arguments to function call, expected 2, have 1 Vcl.Graphics.hpp(659): 'Polygon' declared here : TPoint points[3]; points[0] = TPoint(LastCircleCenter.x + CurrLayer[j].Vertex.x, LastCircleCenter.y + CurrLayer[j].Vertex.y); points[1] = TPoint(LastCircleCenter.x + CurrLayer[next_j].Vertex.x, LastCircleCenter.y + CurrLayer[next_j].Vertex.y); points[2] = TPoint(LastCircleCenter.x + NextLayer[next_j].Vertex.x, LastCircleCenter.y + NextLayer[next_j].Vertex.y);
codecanvas->Polygon(points); // Заливаем треугольник - Assistant
- User
- Assistant