Как рассчитать все параметры треугольника?

Для расчета основных параметров треугольника (таких как: периметр, площадь, длины сторон, углы, координаты, радиусы вписанной и описанной окружностей, а также координаты их центров) можно воспользоваться следующим классом TTriangle. Все формулы, используемые в коде, а также пример работы класса в практической реализации см. на странице "Расчет треугольника"

 
TTriangle = class
  private
    fx1, fy1 : Double;
    fx2, fy2 : Double;
    fx3, fy3 : Double;
    function GetDistAB: Double;
    function GetDistAC: Double;
    function GetDistBC: Double;
    function GetPerimeter: Double;
    function GetArea: Double;
    function GetAngleA: Double;
    function GetAngleB: Double;
    function GetAngleC: Double;
    function GetRadiusIn: Double;
    function GetRadiusOut: Double;
    function GetCenterOut: TFPoint;
    function GetCenterIn: TFPoint;
    function PointsInLine: Boolean;
  public
    // Задание треугольника координатами его вершин
    constructor Create( ax1,ay1, ax2,ay2, ax3,ay3: Double); overload;
    // Задание треугольника длинами его сторон
    constructor Create( a, b, c: Double); overload;
    //функция нахождения длины отрезка
    function Dist( ax1, ay1, ax2, ay2: Double): Double;   
  published
    // координаты первой вершины A
    property X1: Double read fx1 write fx1;
    property Y1: Double read fy1 write fy1;
    // координаты второй вершины B
    property X2: Double read fx2 write fx2;
    property Y2: Double read fy2 write fy2;
    // координаты третьей вершины С
    property X3: Double read fx3 write fx3;
    property Y3: Double read fy3 write fy3;
    property DistAB: Double read GetDistAB; // Длина AB
    property DistBC: Double read GetDistBC; // Длина BC
    property DistAC: Double read GetDistAC; // Длина AC
    property Perimeter: Double read GetPerimeter; // Периметр
    property Area: Double read GetArea;  // Площадь
    property AngleA: Double read GetAngleA; // Угол A
    property AngleB: Double read GetAngleB; // Угол B
    property AngleC: Double read GetAngleC; // Угол C
    // Радиус вписанной окружности
    property RadiusIn: Double read GetRadiusIn;
    // Радиус описанной окружности 
    property RadiusOut: Double read GetRadiusOut;
    // Центр описанной окружности
    property CenterOut: TFPoint read  GetCenterOut;
    // Центр вписанной окружности
    property CenterIn: TFPoint read  GetCenterIn;
  end;
 
{ TTriangle }
 
constructor TTriangle.Create(ax1, ay1, ax2, ay2, ax3, ay3: Double);
begin
  fx1 := ax1;
  fy1 := ay1;
  fx2 := ax2;
  fy2 := ay2;
  fx3 := ax3;
  fy3 := ay3;
end;
 
 
constructor TTriangle.Create(a, b, c: Double);
Var cosa: Double;
begin
  fx1 := 0;
  fy1 := 0;
  fx2 := 0;
  fy2 := c;
  cosa := (b*b+c*c - a*a)/(2*b*c);
  fy3 := b * cosa;
  fx3 := b * sin(arccos(cosA));
end;
 
 
function TTriangle.Dist(ax1, ay1, ax2, ay2: Double): Double;
begin
 Result := sqrt((ax2-ax1)*(ax2-ax1)+(ay2-ay1)*(ay2-ay1));
end;
 
 
function TTriangle.GetAngleA: Double;
Var a, r: Double;
begin
 a := (fx2-fx1)*(fx3-fx1)+(fy2-fy1)*(fy3-fy1);
 r := a/DistAB/DistAC;
 Result := arccos(r);
end;
 
 
function TTriangle.GetAngleB: Double;
Var a, r: Double;
begin
 a := (fx1-x2)*(fx3-fx2)+(fy1-fy2)*(fy3-fy2);
 r := a/DistAB/DistBC;
 Result := arccos(r);
end;
 
 
function TTriangle.GetAngleC: Double;
Var a, r: Double;
begin
 a := (fx2-x3)*(fx1-fx3)+(fy2-fy3)*(fy1-fy3);
 r := a/DistBC/DistAC;
 Result := arccos(r);
end;
 
 
function TTriangle.GetArea: Double;
begin
 Result := sqrt((Perimeter/2*(Perimeter/2-DistAB)*
                (Perimeter/2-DistBC)*(Perimeter/2-DistAC)));
end;
 
 
function TTriangle.GetCenterIn: TFPoint;
Var
  Lc, Lb, La             : Double;
  cx, cy, bx, by, ax, ay : Double; 
  K1, K2                 : Double;
begin
  Lb := DistBC/DistAB;
  Lc := DistBC/DistAC;
 
  cx := (fx2+Lc*fx1)/(Lc+1);
  cy := (fy2+Lc*fy1)/(Lc+1);
 
  bx := (fx3+Lb*fx1)/(Lb+1);
  by := (fy3+Lb*fy1)/(Lb+1);
 
  if cx <> fx3 then K1 := (cy-fy3)/(cx-fx3) else K1 := 1e+96;
  if bx <> fx2 then K2 := (by-fy2)/(bx-fx2) else K2 := 1e+96;
 
  Result.x := (K1*fx3-K2*fx2+(fy2-fy3))/(K1-K2);
  if Result.x <> fx3 then
    Result.y := K1*(Result.x-fx3)+fy3
  else
    Result.y := K2*(Result.x-fx2)+fy2;
end;
 
 
function TTriangle.GetCenterOut: TFPoint;
Var ma, mb : Double;  //  коэффициенты наклона линий
begin
  if fx2 <> fx1 then ma := (fy2-fy1)/(fx2-fx1) else ma := 1e95;
  if fx3 <> fx2 then mb := (fy3-fy2)/(fx3-fx2) else mb := 1e95;
  Result.x := (ma*mb*(fy1-fy3) + mb*(fx1+fx2) - 
               ma*(fx2+fx3))/(2*(mb-ma));
  if ma <> 0 then
    Result.y :=  -1/ma*(Result.x - (fx1+fx2)/2) + (fy1+fy2)/2
  else
    Result.y :=  -1/mb*(Result.x - (fx2+fx3)/2) + (fy2+fy3)/2;
end;
 
 
function TTriangle.GetDistAB: Double;
begin
  Result := Dist ( fx1, fy1, fx2, fy2);
end;
 
 
function TTriangle.GetDistAC: Double;
begin
  Result := Dist ( fx1, fy1, fx3, fy3);
end;
 
 
function TTriangle.GetDistBC: Double;
begin
  Result := Dist ( fx2, fy2, fx3, fy3);
end;
 
 
function TTriangle.GetPerimeter: Double;
begin
  Result := DistAB + DistBC + DistAC;
end;
 
 
function TTriangle.GetRadiusIn: Double;
begin
  if not PointsInLine then
    Result := 2 * Area / Perimeter;
end;
 
 
function TTriangle.GetRadiusOut: Double;
begin
  if not PointsInLine then
    Result := (DistAB*DistBC*DistAC)/(4*Area);
end;
 
 
function TTriangle.PointsInLine: Boolean;
Var a : double;
begin
  Result := false;
  a := fx1*fy2+fx2*fy3+fx3*fy1-fx3*fy2-fx2*fy1-fx1*fy3;
  if abs(a - 1e-20) < 1e-19 then
    Result := true;
end;

Пример использования класса для задачи "Как найти площадь треугольника, заданного длинами сторон a=10, b=12, c=11?"

procedure TForm1.Button1Click(Sender: TObject);
Var T: TTriangle;
begin
   T := TTriangle.Create( 10, 12, 11);
   showmessage( FloatToStr( T.Area));
end;

Пример использования класса для задачи "Как найти периметр треугольника, заданного координатами вершин A(0,0), B(1,0), C(1,1)?"

procedure TForm1.Button1Click(Sender: TObject);
Var T: TTriangle;
begin
   T := TTriangle.Create( 0, 0, 1, 0, 1, 1);
   showmessage(FloatToStr( T.Perimeter));
end;

Отправил JamesDeK Чт, 02/06/2020 - 19:10

cheap legal cialis buy viagra jelly buy cialis au

Отправил Georgelic Чт, 02/06/2020 - 16:13

cialis 2.5mg pills over the counter viagra cheap viagra australia

Отправил JamesDeK Чт, 02/06/2020 - 11:08

cheap cialis daily online order for cialis best place to buy generic cialis

Отправил Shawnvub Чт, 02/06/2020 - 09:53

how to buy cialis online from canada https://edmedz.com cheap levitra no prescription

Отправил Robertincef Чт, 02/06/2020 - 09:03

order cialis phone where to buy levitra in canada generic levitra online cheap

Отправил Georgelic Чт, 02/06/2020 - 05:28

buy cialis kuala lumpur ordering viagra online legal very cheap viagra uk

Отправил JohnnyKak Чт, 02/06/2020 - 03:56

where can i buy viagra online yahoo answers buy generic viagra cheap cheap viagra brand

Отправил JamesDeK Чт, 02/06/2020 - 02:54

viagra sale ireland discount cialis online no prescription order real cialis

Отправил Robertincef Чт, 02/06/2020 - 01:42

buy levitra overnight cialis 20 mg tablets uk viagra cheap from canada

Отправил Shawnvub Ср, 02/05/2020 - 21:20

best place buy generic cialis https://edmedz.com discount cialis pills

Отправил JamesDeK Ср, 02/05/2020 - 18:14

cheap levitra generic can buy viagra dubai generic levitra cheapest prices

Отправил Robertincef Ср, 02/05/2020 - 18:04

buy generic cialis online in usa buy cialis online generic viagra buy uk cheap

Отправил Georgelic Ср, 02/05/2020 - 17:34

discount cialis cheap cialis brand cheapest cialis india

Отправил JohnnyKak Ср, 02/05/2020 - 15:24

viagra for women for sale in the uk generic cialis on sale safe place order viagra online

Отправил Robertincef Ср, 02/05/2020 - 10:29

viagra sale phone cheapest viagra professional best place buy cialis online forum

Отправил JamesDeK Ср, 02/05/2020 - 09:48

cialis how to buy price of cialis buy cheap cialis online no prescription

Отправил Shawnvub Ср, 02/05/2020 - 08:46

cheapest viagra kamagra https://edmedz.com purchase cialis online cheap

Отправил Georgelic Ср, 02/05/2020 - 05:32

cialis buy australia site es cheap viagra cialis soft tabs 20mg pills

Отправил JohnnyKak Ср, 02/05/2020 - 03:41

buy online prescription viagra without brand levitra cheap best place buy cialis online uk

Отправил Robertincef Ср, 02/05/2020 - 03:00

viagra + where to buy + .au buy cheap levitra online buy cialis online without rx

Отправил JamesDeK Ср, 02/05/2020 - 00:51

buy levitra with no prescription cheap viagra sale generic cialis cost

Отправил Shawnvub Втр, 02/04/2020 - 20:45

cheap-levitra.com https://edmedz.com buy cialis online london

Отправил Robertincef Втр, 02/04/2020 - 19:33

generic viagra pills viagra for sale at tesco can you order cialis

Отправил Georgelic Втр, 02/04/2020 - 18:03

cheap viagra cialis uk cialis 20 mg price walmart buy viagra boots

Отправил JamesDeK Втр, 02/04/2020 - 15:40

viagra usa buy cheap viagra sale uk viagra generic name

Отправил JohnnyKak Втр, 02/04/2020 - 10:14

cheapest place buy cialis online cialis sale philippines viagra super active for sale&39;

Отправил Chestertearo Втр, 02/04/2020 - 08:21

cialis pills for sale uk buy cialis from australia buy cialis euro

Отправил Shawnvub Втр, 02/04/2020 - 07:05

cheap viagra no rx https://edmedz.com hard sale evolution viagra salesman

Отправил JamesDeK Втр, 02/04/2020 - 06:19

where can i buy levitra canadian pharmacy cialis viagra buy online australia

Отправил Georgelic Втр, 02/04/2020 - 04:30

buy levitra from germany cheap levitra liquid viagra buy uk

Отправил JohnnyKak Пнд, 02/03/2020 - 23:37

cheap viagra real very nice site cheap viagra buying cialis online uk

Отправил Chestertearo Пнд, 02/03/2020 - 21:54

levitra for sale no prescription levitra buy australia buy viagra plus

Отправил Robertincef Пнд, 02/03/2020 - 21:33

buy cialis usa cheap viagra generic pills buy viagra online to canada

Отправил JamesDeK Пнд, 02/03/2020 - 21:28

cheap cialis next day shipping discount generic cialis 20mg cheap viagra pills

Отправил Shawnvub Пнд, 02/03/2020 - 17:12

buy genuine viagra https://edmedz.com can buy viagra uk

Отправил Georgelic Пнд, 02/03/2020 - 15:19

cialis from india order viagra online nz buy viagra online without rx

Отправил Robertincef Пнд, 02/03/2020 - 13:56

can you buy viagra rite aid buy viagra online buy viagra discount

Отправил JohnnyKak Пнд, 02/03/2020 - 12:35

cialis pills women goodrx viagra buy generic levitra australia

Отправил JamesDeK Пнд, 02/03/2020 - 12:30

discount for cialis viagra super force 100mg 100mg pills buy viagra los angeles

Отправил Chestertearo Пнд, 02/03/2020 - 10:36

buy viagra cialis uk buying cialis online canada cialis for sale in philippines

Отправил Robertincef Пнд, 02/03/2020 - 06:31

how to buy viagra online buy viagra philippines discount levitra pills

Отправил JamesDeK Пнд, 02/03/2020 - 03:08

order cialis online mastercard generic cialis online buy viagra super active+ 100mg pills

Отправил JohnnyKak Пнд, 02/03/2020 - 00:42

buy levitra online in canada can i buy cialis in dubai viagra sale in canada

Отправил Chestertearo Вс, 02/02/2020 - 23:32

cheapest brand cialis online buy cialis online mastercard buy viagra cialis uk

Отправил Robertincef Вс, 02/02/2020 - 22:36

generic name for viagra order viagra for men buy generic cialis online uk

Отправил JamesDeK Вс, 02/02/2020 - 16:36

buy cialis one a day buy generic cialis no prescription where can i buy viagra in japan

Отправил Georgelic Вс, 02/02/2020 - 16:32

can buy cheap viagra buy viagra manila viagra sale scotland

Отправил Shawnvub Вс, 02/02/2020 - 16:13

buy cialis us pharmacy https://edmedz.com cialis buy online canada

Отправил Robertincef Вс, 02/02/2020 - 15:16

how much viagra should i take the first time? cheapest viagra cialis levitra buy cialis england

Отправил Chestertearo Вс, 02/02/2020 - 12:53

cialis pills from india cialis average wholesale price viagra sale next day delivery

Последние комментарии

Счетчики