Используя этот код: Unit1.h -…
- User
Используя этот код: Unit1.h - //--------------------------------------------------------------------------- #ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include <System.Classes.hpp> #include <Vcl.Controls.hpp> #include <Vcl.StdCtrls.hpp> #include <Vcl.Forms.hpp> #include <Vcl.ExtCtrls.hpp> #include <Vcl.Grids.hpp> #include //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TPaintBox PaintBox1; void __fastcall PaintBox1Click(TObject *Sender); private: // User declarations 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::vectorstd::vector Layers; //--------------------------------------------------------------------------- extern PACKAGE TForm1 Form1; //--------------------------------------------------------------------------- #endif В Unit1.cpp - //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include <math.h> #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) { } //--------------------------------------------------------------------------- void __fastcall TForm1::PaintBox1Click(TObject *Sender) { Canvas->Pen->Color = clBlack; Canvas->Pen->Width = 2; double centerX = PaintBox1->Width / 2; double centerY = PaintBox1->Height / 2; int scale = 8; double r1 = 10; double r2 = 50; double total_area = M_PI * (r2 * r2 - r1 * r1); double filled_area = 0; double length = 6.28; // длина стороны треугольника
Points.clear(); Layers.clear();
int number_layers = ceil((r2 - r1) / length) + 1; double h = (r2 - r1) / (number_layers - 1);
for (int i = 0; i < number_layers; i++) { double radius_layer = r1 + i * h; int number_points = ceil(2 * M_PI * radius_layer / length); double alpha = 2 * M_PI / number_points; std::vector Points_layer; for (int j = 0; j < number_points; j++) { TPoint2D Point; Point.Vertex.number = Points.size(); Point.Vertex.x = radius_layer * cos(j * alpha); Point.Vertex.y = radius_layer * sin(j * alpha); Points.push_back(Point); Points_layer.push_back(Point); } Layers.push_back(Points_layer); }
for (int i = 0; i < number_layers - 1; i++) { auto& Layer1 = Layers[i]; auto& Layer2 = Layers[i + 1]; int number_points_1 = Layer1.size(); int number_points_2 = Layer2.size();
- Assistant
- User
- Assistant
- User
Он рисует треугольники не относительно центра окружности, а относительно краев. При чем делает это так, как будто поверхность не круг, а бублик
- Assistant
- User
Он все равно не заполняет центр окружности! Нужно сделать так, чтобы заполнение треугольниками шло от центра окружности, и одна из вершин первых треугольников обязательно бы была в центре окружности
- Assistant
- User
Теперь он рисует из центра, первые фигуры получаются треугольниками, но дальше они идут четерехугольниками, а должны быть треугольники, две вершины которых совпадают с двумя вершинами треугольников из предыдущих слоёв
- Assistant
- User
Ничего не изменилось, получается так, что в каждом слое одна вершина треугольника совпадает с центром окружности, а так должно быть только у первых слоев треугольников. У вторых и последующих должно быть две общих вершины (грань) с предыдущим слоем.
- Assistant
- User
Он теперь просто делит круг на сектора, а не на треугольники
- Assistant