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

Для расчета основных параметров треугольника (таких как: периметр, площадь, длины сторон, углы, координаты, радиусы вписанной и описанной окружностей, а также координаты их центров) можно воспользоваться следующим классом 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;

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

cialis canada buy cialis online pharmacy buy cialis generic canada

Отправил Thomashoode Вс, 02/16/2020 - 11:52

illegal to order viagra online high blood pressure and cialis safest place to buy cialis online

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

order cialis no prescription canada http://tadmedz.com best online pharmacy to buy cialis

Отправил Thomashoode Вс, 02/16/2020 - 04:20

discount cialis cialis lowest price 20mg order cialis online with mastercard

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

cheapest cialis tablets which is better - cialis or viagra levitra pills for sale

Отправил Thomashoode Сб, 02/15/2020 - 21:23

buy+cialis+online+without+prescription+in+canada price of cialis order viagra in us

Отправил Shawnvub Сб, 02/15/2020 - 16:54

cheap 2.5 mg cialis http://tadmedz.com cheapest viagra super force

Отправил BrandonMes Сб, 02/15/2020 - 14:57

buy cialis in belgium does medicaid cover cialis viagra sale vancouver

Отправил FuenceMup Сб, 02/15/2020 - 14:13

where can i buy viagra side effects for cialis viagra professional pills

Отправил Thomashoode Сб, 02/15/2020 - 14:10

order levitra now cialis 200mg generic cialis 2019

Отправил Thomashoode Сб, 02/15/2020 - 07:06

buy cheap cialis line cialis prices 20mg cuanto sale el viagra en farmacias

Отправил BrandonMes Сб, 02/15/2020 - 03:24

order viagra with no prescription online which is better - cialis or viagra order viagra without rx online

Отправил Shawnvub Сб, 02/15/2020 - 03:19

legal buy viagra online http://tadmedz.com cheap viagra canadian pharmacy

Отправил FuenceMup Сб, 02/15/2020 - 01:01

is it legal to order cialis online cialis 20 mg best price cheap viagra generic canada

Отправил Thomashoode Сб, 02/15/2020 - 00:05

cheap/discount cialis cialis coupon can you really buy viagra online

Отправил Thomashoode Пт, 02/14/2020 - 16:53

cialis super active sale cialis coupon code order herbal viagra

Отправил BrandonMes Пт, 02/14/2020 - 15:53

viagra buy singapore п»їcialis viagra sale britain

Отправил Shawnvub Пт, 02/14/2020 - 14:23

mail order viagra online http://tadmedz.com legal buy generic cialis

Отправил FuenceMup Пт, 02/14/2020 - 12:14

viagra sale online canada cialis coupons order viagra men

Отправил Thomashoode Пт, 02/14/2020 - 10:12

order generic cialis online canada how to get cialis samples himalayan viagra sale

Отправил Thomashoode Пт, 02/14/2020 - 03:27

viagra online australia cheap cialis online viagra buy perth

Отправил BrandonMes Пт, 02/14/2020 - 03:10

levitra buy cheap herbal replacement for viagra/cialis/levitra... where to get cialis cheap

Отправил Shawnvub Пт, 02/14/2020 - 00:26

buy brand cialis online no prescription http://tadmedz.com cheap levitra in canada

Отправил FuenceMup Чт, 02/13/2020 - 23:05

how to buy a viagra real cialis without a doctor's prescription how to buy viagra or cialis

Отправил Thomashoode Чт, 02/13/2020 - 21:11

buy cialis south africa cialis price cheap viagra canada

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

levitra prix discount http://tadmedz.com buy cheap cialis usa visa http://cialisxtl.com generic viagra cheap shipping

Отправил Thomashoode Чт, 02/13/2020 - 14:12

viagra sale online ireland cheap cialis order viagra from mexico

Отправил Shawnvub Чт, 02/13/2020 - 10:50

best place buy generic cialis online http://tadmedz.com viagra sale in australia

Отправил FuenceMup Чт, 02/13/2020 - 09:46

viagra sale adelaide cialis before and after canada viagra

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

viagra sale mississauga http://tadmedz.com is it legal to order viagra online in canada http://cialisxtl.com buy viagra online canada

Отправил Thomashoode Чт, 02/13/2020 - 07:35

order brand cialis online cialis and interaction with ibutinib discount cialis viagra

Отправил JamesDeK Чт, 02/13/2020 - 00:55

order viagra online safe http://tadmedz.com order cheap cialis online http://cialisxtl.com buy viagra canada online

Отправил Thomashoode Чт, 02/13/2020 - 00:50

viagra sale nhs is cialis generic available order viagra internet

Отправил BrandonMes Ср, 02/12/2020 - 22:46

cialis viagra sale canada cialis 20 mg best price cialis brand cheap

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

cheap generic levitra http://tadmedz.com buy levitra online

Отправил FuenceMup Ср, 02/12/2020 - 20:34

discount genuine cialis cialis coupons printable buy viagra in london

Отправил Thomashoode Ср, 02/12/2020 - 17:45

prices of cialis cialis prices order viagra south africa

Отправил JamesDeK Ср, 02/12/2020 - 17:38

can you buy cialis over counter mexico http://tadmedz.com can you buy cialis online http://cialisxtl.com buy cialis professional cheap

Отправил LizkaCrype Ср, 02/12/2020 - 12:30

I'm Lisa, I'm new to you here.
I want to connect with a guy to communicate.
Write to qb2020bq@gmail.com.

Отправил LizkaCrype Ср, 02/12/2020 - 12:28

Hello, everybody, I'm Lisa.
Looking for a nice guy: Kind, not stupid, who will not be bored with learning and self-development.

Write to qb2020bq@gmail.com.

Отправил JamesDeK Ср, 02/12/2020 - 08:30

cialis coupon walgreens viagra cheap in canada cialis at discount price

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

buy viagra with paypal over the counter cialis can you buy cialis online in australia

Отправил Shawnvub Ср, 02/12/2020 - 03:12

buy cheap viagra cialis https://edmedz.com order viagra canada online

Отправил Georgelic Ср, 02/12/2020 - 01:56

viagra cheap canadian pharmacy order viagra now buy cheap cialis super active

Отправил JamesDeK Втр, 02/11/2020 - 22:59

discount canadian cialis viagra sale spain cialis rush order

Отправил JohnnyKak Втр, 02/11/2020 - 22:11

cheap cialis australia order cialis cheap old do u have buy viagra

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

viagra buy in usa buy generic cialis uk order viagra cialis canada

Отправил Shawnvub Втр, 02/11/2020 - 15:43

cheap levitra no prescription https://edmedz.com buy cialis daily

Отправил Georgelic Втр, 02/11/2020 - 14:28

cialis sale philippines order cialis prescription how to order generic cialis

Отправил JamesDeK Втр, 02/11/2020 - 13:20

how much is cialis [url=https://edmedz.com/#]cheap mexico viagra[/url] cheapest cialis online

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

Счетчики