Есть код для C++ Builder, который строит окружности, а потом делит заполняет окружности…
- User
Есть код для C++ Builder, который строит окружности, а потом делит заполняет окружности треугольниками. Нужно добавить в код, чтобы для абсолютно каждого треугольника считались три длины его сторон и находилась большая из них. Потом находилась координата середины большей стороны, к которой бы из вершины, противолежащей большей стороне, проводилась точка к ее середине. Сделать это нужно через введение новых функций. Вот код: В 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; TLabel *Label1; TEdit *Edit2; TLabel *Label2; void __fastcall Button1Click(TObject *Sender); void __fastcall Button2Click(TObject *Sender); void __fastcall Button3Click(TObject *Sender); // Изменен обработчик для заполнения
private:
TPoint 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::vectorstd::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
Напиши полный исправленный код для void TForm1::DrawTriangulation()
- Assistant
- User
[bcc32c Error] Unit1.h(40): unknown type name 'Triangle' в void ProcessTriangle(const Triangle& triangle); [bcc32c Error] Unit1.h(42): unknown type name 'TPoint2D' в double GetSideLength(const TPoint2D& p1, const TPoint2D& p2); TPoint2D GetMidpoint(const TPoint2D& p1, const TPoint2D& p2);
- Assistant
- User
[bcc32c Error] Unit1.h(40): unknown type name 'Triangle' в void ProcessTriangle(const Triangle& triangle);
- Assistant