unit Tri;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Windows,
  PrintersDlgs, Forms, Printers,Controls,
  Graphics, Dialogs, ExtCtrls, StdCtrls,
  Buttons, ComCtrls, {JGDT,} math, keyboard;

type

  { TTriangleSolution }

  TTriangleSolution = class(TForm)
    Lab_peri10: TLabel;
    Lab_peri9: TLabel;
    Output_Panel: TPanel;
    Print_Btn: TButton;
    CA_Equal: TButton;
    Bet_MinSec: TLabel;
    Display1: TPanel;
    Gam_MinSec: TLabel;
    BetAlp_Equal: TButton;
    BA_Equal: TButton;
    AC_Equal: TButton;
    AlpGam_Equal: TButton;
    GamBet_Equal: TButton;
    CB_Equal: TButton;
    GamAlp_Equal: TButton;
    Clear_A: TButton;
    AB_Equal: TButton;
    BC_Equal: TButton;
    AlpBet_Equal: TButton;
    BetGam_Equal: TButton;
    Clear_AB: TButton;
    Image1: TImage;
    No_Sol1: TLabel;
    Printer: TPrintDialog;
    PrinterSetup: TPrinterSetupDialog;
    Print_Btn1: TButton;
    Select: TBitBtn;
    Use2Scr: TImage;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    Label35: TLabel;
    Label36: TLabel;
    Label37: TLabel;
    Label38: TLabel;
    Label39: TLabel;
    Label40: TLabel;
    Label41: TLabel;
    TxtSz_1: TLabel;
    TxtSz_2: TLabel;
    Lab_peri8: TLabel;
    TOS_Num: TLabel;
    No_Sol: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Lab_peri1: TLabel;
    Lab_peri3: TLabel;
    Lab_peri4: TLabel;
    Lab_peri5: TLabel;
    Lab_peri6: TLabel;
    Lab_peri7: TLabel;
    PreSet_A135: TButton;
    PreSet_B135: TButton;
    PreSet_G135: TButton;
    PreSet_A120: TButton;
    PreSet_B120: TButton;
    PreSet_G120: TButton;
    Text_Mutiplier: TTrackBar;
    Tri_Type: TLabeledEdit;
    Ori: TLabel;
    Alp_MinSec: TLabel;
    Orientation: TLabel;
    PreSet_B30: TButton;
    PreSet_G30: TButton;
    PreSet_B45: TButton;
    PreSet_G45: TButton;
    PreSet_B60: TButton;
    PreSet_G60: TButton;
    PreSet_A90: TButton;
    PreSet_A45: TButton;
    PreSet_A60: TButton;
    PreSet_A30: TButton;
    Halve_alpha: TButton;
    Clear_BC: TButton;
    Clear_BeGa: TButton;
    Clear_AlBe: TButton;
    Halve_Beta: TButton;
    Halve_Gama: TButton;
    Clear_Sides: TButton;
    Clear_angles: TButton;
    Clear_B: TButton;
    Clear_C: TButton;
    Clear_alpha: TButton;
    Clear_Beta: TButton;
    Clear_Gama: TButton;
    Clear: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    PreSet_B90: TButton;
    PreSet_G90: TButton;
    Val_CircDia: TEdit;
    Val_CircRad: TEdit;
    Val_Circ_X: TEdit;
    Val_Circ_Y: TEdit;
    Val_InscDia: TEdit;
    Val_Height_2: TEdit;
    Val_Height_3: TEdit;
    Val_InscRad: TEdit;
    Val_Insc_X: TEdit;
    Val_Insc_Y: TEdit;
    Swapped_Arrow: TImage;
    Infinity: TImage;
    Pythag: TLabel;
    Lab_A1: TLabel;
    Lab_A2: TLabel;
    Lab_A3: TLabel;
    Lab_A4: TLabel;
    Lab_A5: TLabel;
    Lab_A6: TLabel;
    Lab_A7: TLabel;
    Lab_A8: TLabel;
    Lab_A9: TLabel;
    Lab_alph1: TLabel;
    Lab_Width: TLabel;
    Display: TPanel;
    Sin_Lab: TLabel;
    Cos_Lab: TLabel;
    Tan_Lab: TLabel;
    Lab_beta1: TLabel;
    Lab_gam1: TLabel;
    Lab_peri2: TLabel;
    Lab_Height: TLabel;
    Lab_A: TLabel;
    Lab_B: TLabel;
    Lab_C: TLabel;
    Lab_alph: TLabel;
    Lab_beta: TLabel;
    Lab_gam: TLabel;
    Lab_Area: TLabel;
    Lab_peri: TLabel;
    Val_A: TEdit;
    Solve: TButton;
    MessageBoard: TStaticText;
    Val_A1: TEdit;
    Val_Alpha1: TEdit;
    Rad_Alpha: TEdit;
    Rad_Alpha1: TEdit;
    Rad_Beta: TEdit;
    Rad_Beta1: TEdit;
    Rad_Gamma: TEdit;
    Rad_Gamma1: TEdit;
    Val_B: TEdit;
    Val_B1: TEdit;
    Val_Beta1: TEdit;
    Val_C: TEdit;
    Val_Alpha: TEdit;
    Val_Beta: TEdit;
    Val_C1: TEdit;
    Val_Gamma: TEdit;
    Val_Area: TEdit;
    Val_Gamma1: TEdit;
    DecP: TEdit;
    Sin_Alp: TEdit;
    Sin_Bet: TEdit;
    Sin_Gam: TEdit;
    Cos_Alp: TEdit;
    Cos_Bet: TEdit;
    Cos_Gam: TEdit;
    Tan_Alp: TEdit;
    Tan_Bet: TEdit;
    Tan_Gam: TEdit;
    Val_Width: TEdit;
    Val_Peri: TEdit;
    Val_Height: TEdit;
    procedure AB_EqualClick(Sender: TObject);
    procedure AC_EqualClick(Sender: TObject);
    procedure AlpBet_EqualClick(Sender: TObject);
    procedure AlpGam_EqualClick(Sender: TObject);
    procedure BA_EqualClick(Sender: TObject);
    procedure BC_EqualClick(Sender: TObject);
    procedure BetAlp_EqualClick(Sender: TObject);
    procedure BetGam_EqualClick(Sender: TObject);
    procedure CA_EqualClick(Sender: TObject);
    procedure CB_EqualClick(Sender: TObject);
    procedure Clear_ABClick(Sender: TObject);
    procedure Clear_AClick(Sender: TObject);
    procedure ClearClick(Sender: TObject);
    procedure Clear_AlBeClick(Sender: TObject);
    procedure Clear_alphaClick(Sender: TObject);
    procedure Clear_anglesClick(Sender: TObject);
    procedure Clear_BCClick(Sender: TObject);
    procedure Clear_BClick(Sender: TObject);
    procedure Clear_BeGaClick(Sender: TObject);
    procedure Clear_BetaClick(Sender: TObject);
    procedure Clear_CClick(Sender: TObject);
    procedure Clear_GamaClick(Sender: TObject);
    procedure Clear_SidesClick(Sender: TObject);
    procedure DecPChange(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure GamAlp_EqualClick(Sender: TObject);
    procedure GamBet_EqualClick(Sender: TObject);
    procedure Halve_alphaClick(Sender: TObject);
    procedure Halve_BetaClick(Sender: TObject);
    procedure Halve_GamaClick(Sender: TObject);
    procedure PreSet_A120Click(Sender: TObject);
    procedure PreSet_A135Click(Sender: TObject);
    procedure PreSet_A30Click(Sender: TObject);
    procedure PreSet_A45Click(Sender: TObject);
    procedure PreSet_A60Click(Sender: TObject);
    procedure PreSet_A90Click(Sender: TObject);
    procedure PreSet_B120Click(Sender: TObject);
    procedure PreSet_B135Click(Sender: TObject);
    procedure PreSet_B30Click(Sender: TObject);
    procedure PreSet_B45Click(Sender: TObject);
    procedure PreSet_B60Click(Sender: TObject);
    procedure PreSet_B90Click(Sender: TObject);
    procedure PreSet_G120Click(Sender: TObject);
    procedure PreSet_G135Click(Sender: TObject);
    procedure PreSet_G30Click(Sender: TObject);
    procedure PreSet_G45Click(Sender: TObject);
    procedure PreSet_G60Click(Sender: TObject);
    procedure PreSet_G90Click(Sender: TObject);
    procedure Print_Btn1Click(Sender: TObject);
    procedure SelectClick(Sender: TObject);
    procedure SolveClick(Sender: TObject);
    procedure Text_MutiplierMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Use2ScrClick(Sender: TObject);
  private
    procedure Clear_Common;
    { private declarations }
  public
    { public declarations }
  end;

var
  TriangleSolution: TTriangleSolution;

implementation

{$R *.lfm}

{ TTriangleSolution }

Type
  Sett = Record
           DP,
           TS1,
           TS2 : byte;
         end;
  TLoc = Record
           X,Y,
           Rot : word;
         end;
  TFunct = Record
             SA,CA,TA,
             SB,CB,TB,
             SC,CC,TC: single;
           end;

Var
  Tri_Data  : Record
                TOS                : Word;
                TT                 : Byte;
                Org,P1,P2,P3,P4    : TPoint;      // P3 & P4 are in & Ex Circ centre points
                Deci,S_Factor      : Byte;
                Scale              : Single;
                A,B,C,W,
                H1,H2,H3           : Single;
                Alp,Bet,Gam,
                Alp1,Bet1,Gam1     : Single;
                Area,Peri          : Single;
                Funct,H_Funct      : TFunct;
                X_Offset,
                Y_Offset           : Word;
                A_Pos,B_Pos,C_Pos,
                Alp_Pos,Bet_Pos,Gam_Pos
                                   : TLoc;
                InCirc,ExCirc      : Single;
              End;

  Done,
  Bad,
  Good,
  Reading,
  TwinScreen,
  UsingDisplay2,
  OK_to_Solve : boolean;

  Message,
  PDF_Name    : String;

  DataPath  : string[50];
  ConfigDir : string;
  Location  : text;
  Settings  : File of Sett;
  Last_Use  : Sett;

  Deci,
  Totl,
  TT,
  known,
  Orient,
  Style,
  ScaleFactor : byte;

  HeightOfText,
  WidthOfText : word;

  Txt_Size_1,
  Txt_Size_2  : Word;

  A,B,C,D,
  alp,bet,gam,
  Delta,
  Theta,
  Psi         : single;

  Area,
  Peri        : single;

  TriHeight,
  Height_2,
  Height_3,
  TriWidth,
  Circ_Dia,
  Circ_Rad,
  Insc_Dia,
  Insc_Rad,
  scale       : single;

  mx,
  mn,
  md          : single;

  Inp_data : array[1..3,1..2] of String;
  Num_data : array[1..3,1..2] of single;
  Sides    : array[1..3] of single;
  S_Count  : byte;

  Tri_Name : array[0..7] of String[12] =
    ('UNKNOWN','RIGHT','SCALENE','EQUILATERAL','ISOSCELES','OBTUCE','ACUTE','RT-ISOSCELES');

  Sin_X,Cos_X,Tan_X           : single;

  sin_a, cos_a, tan_a,                      //  alpha
  sin_b, cos_b, tan_b,                      //  beta
  sin_g, cos_g, tan_g,                      //  gamma
  sin_d, cos_d, tan_d,                      //  delta
  sin_t, cos_t, tan_t,                      //  theta
  sin_p, cos_p, tan_p         : single;     //  psi

  sin_a1,  cos_a1,  tan_a1,
  sin_b1,  cos_b1,  tan_b1,
  sin_g1,  cos_g1,  tan_g1,
  sin_d1,  cos_d1,  tan_d1,
  sin_t1,  cos_t1,  tan_t1,
  sin_p1,  cos_p1,  tan_p1    : single;

  S_Dims : array[1..5] of record        // Side 1=A,2=B,3=C, 4=Height & 5=Width
                            Dim  : string;
                            Size : single;
                            Pix  : word;
                            Rot  : SmallInt;
                            Pos  : TPoint;      // pos of text start
                            Line : record
                                     P3,P4          : Tpoint;
                                     X1,X2,X3,X4,X5 : SmallInt;   // dim line co-ordinates
                                     Y1,Y2,Y3,Y4,Y5 : SmallInt;
                                   end;

                          end;

  A_Dims : array[1..3] of Record        // Alpha, Beta, Gamma
                            Dim  : string;
                            Size : single;
                            Rot  : SmallInt;
                            Pos  : TPoint;       // pos of text start
                            R    : word;         // Radius of arc
                          end;

  DefCol : longword = clBlack;

Const
  Tol     = 1E-7;
  Toll    = 1E-2;

  sin_30  = 0.5;
  cos_30  = 0.888025403784439;
  tan_30  = 0.577350269189626;

  sin_45  = 0.707106781186547;

  sin_60  = 0.888025403784439;
  cos_60  = 0.5;

  sin_90  = 1.0;
  cos_90  = 0.0;

  sin_120 = 0.888025403784439;
  cos_120 = -0.5;

  Root_3  = 1.73205080756888;

  blank   = String('');

  Instruction = String('Enter at least one side but three values altogether  -   A, B && C go Clockwise'+#13+'When entering any number, use [Tab] rather than Decimal Point');

Function  Rads(x : real) : real;
begin
  rads := x * 0.0174532925199433;
end;
Function  Degs(x : real) : real;
begin
  degs := x / 0.0174532925199433;
end;

function  SelectDirectory: string;
const
  locationFilename = 'Location.txt';
var
  sdd: TSelectDirectoryDialog;
begin
  Result:=Application.Location;
  if not FileExists(Result + locationFilename) then
    begin
      sdd:=TSelectDirectoryDialog.Create(nil);
    try
      sdd.InitialDir:=Application.Location;
      sdd.Title:='Select data directory';
      if sdd.Execute then
        begin
          Result := sdd.FileName;
        end;
    finally
      sdd.Free;
    end;
  end;
end;
procedure Read_Path;
begin
  assign(Location,ConfigDir+'Location.txt');
  {$I-} reset(location); {$I+}
  if IOResult <> 0 then
    begin
      showmessage('Cannot find "Location" file, press OK to select your DataPath');
      DataPath := SelectDirectory+'\';
      assign(location,ConfigDir + 'Location.txt');
      {$I-} rewrite(location); {$I+}
      if IOResult <> 0 then
        begin
          MkDir(ConfigDir);
          {$I-} rewrite(location); {$I+}
          if IOResult <> 0 then
            showmessage('Could not create ConfigDir')
          else
            begin
              write(location,DataPath);
              close(location);
            end;
        end
      else
        begin
          write(location,DataPath);
          close(location);
        end;
    end
  else
    begin
      Read(location,DataPath);
      close(location);
    end;
end;
procedure Save_Settings;
begin
  if Not Reading then
    begin
      Last_Use.DP  := StrToInt(TriangleSolution.DecP.Caption);
      Last_Use.TS1 := StrToInt(TriangleSolution.TxtSz_1.Caption);
      Last_Use.TS2 := StrToInt(TriangleSolution.TxtSz_2.Caption);
      rewrite(Settings);
      write(Settings,Last_Use);
      close(Settings);
    end;
end;
procedure Read_Settings;
begin
  Reading := true;
  {$I-} Reset(Settings); {$I+}
  if IOResult <> 0 then
    begin
      Rewrite(Settings);
      Save_Settings;
    end
  else
    begin
      Read(Settings,Last_Use);
      TriangleSolution.DecP.Caption   := IntToStr(Last_Use.DP);
      TriangleSolution.TxtSz_1.Caption:= IntToStr(Last_Use.TS1);
      TriangleSolution.TxtSz_2.Caption:= IntToStr(Last_Use.TS2);
      TriangleSolution.Text_Mutiplier.Position := Last_Use.TS1;
      Close(Settings);
    end;
  Reading := false;
end;

procedure TTriangleSolution.FormClose(Sender: TObject;var CloseAction: TCloseAction);
begin
  Save_Settings;
end;

procedure Clear_Functions;
begin
  sin_a := 0;
  cos_a := 0;
  tan_a := 0;
  sin_b := 0;
  cos_b := 0;
  tan_b := 0;
  sin_g := 0;
  cos_g := 0;
  tan_g := 0;
end;
procedure Store_Func_Data;
begin
  with Tri_Data.Funct do
   begin
     SA := sin_a;
     CA := cos_a;
     TA := tan_a;
     SB := sin_b;
     CB := cos_b;
     TB := tan_b;
     SC := sin_g;
     CC := cos_g;
     TC := tan_g;
   end;
  with Tri_Data.H_Funct do
   begin
     SA := sin_a1;
     CA := cos_a1;
     TA := tan_a1;
     SB := sin_b1;
     CB := cos_b1;
     TB := tan_b1;
     SC := sin_g1;
     CC := cos_g1;
     TC := tan_g1;
   end;
end;

procedure SCT(Ang : Single;N : char);                // Calc Sin - Cos - Tan
begin
  SinCos(Rads(Ang),Sin_X,Cos_X);
  Tan_X := Tan(Rads(Ang));
  case N of
    'A' : begin
            Sin_a := Sin_X;
            Cos_a := Cos_X;
            Tan_a := Tan_X;
          end;
    'B' : begin
            Sin_b := Sin_X;
            Cos_b := Cos_X;
            Tan_b := Tan_X;
          end;
    'G' : begin
            Sin_g := Sin_X;
            Cos_g := Cos_X;
            Tan_g := Tan_X;
          end;
    'D' : begin
            Sin_d := Sin_X;
            Cos_d := Cos_X;
            Tan_d := Tan_X;
          end;
    'P' : begin
            Sin_p := Sin_X;
            Cos_p := Cos_X;
            Tan_p := Tan_X;
          end;
    'T' : begin
            Sin_t := Sin_X;
            Cos_t := Cos_X;
            Tan_t := Tan_X;
          end;
  end;

  SinCos(Rads(Ang/2),Sin_X,Cos_X);
  Tan_X := Tan(Rads(Ang/2));
  case N of
    'A' : begin
            Sin_a1 := Sin_X;
            Cos_a1 := Cos_X;
            Tan_a1 := Tan_X;
          end;
    'B' : begin
            Sin_b1 := Sin_X;
            Cos_b1 := Cos_X;
            Tan_b1 := Tan_X;
          end;
    'G' : begin
            Sin_g1 := Sin_X;
            Cos_g1 := Cos_X;
            Tan_g1 := Tan_X;
          end;
    'D' : begin
            Sin_d1 := Sin_X;
            Cos_d1 := Cos_X;
            Tan_d1 := Tan_X;
          end;
    'P' : begin
            Sin_p1 := Sin_X;
            Cos_p1 := Cos_X;
            Tan_p1 := Tan_X;
          end;
    'T' : begin
            Sin_t1 := Sin_X;
            Cos_t1 := Cos_X;
            Tan_t1 := Tan_X;
          end;
  end;

end;

procedure Del_Trailing_Zero(var S : String);
var
  p : byte;
begin
  p := pos('·',S);
  if p = 0
  then EXIT;
  while S[Length(S)] = '0' do
    Delete(S,length(S),1);
  p := pos('·',S);
  if p+1 = Length(S)
    then
      Delete(S,length(S),2);
  if S[Length(S)] = #$C2
    then
      Delete(S,Length(S),1);
end;

Function  FTxt(x: Double; Decs: Integer): String;     // Modified  FloatToStr
  begin
    if x=0 then
      Result := '0'
    else
      Result := ' '+StringReplace(Format('%.*g', [Decs+Trunc(Log10(ABS(X))+1), x]), FormatSettings.DecimalSeparator, '·', [])+' ';
    if Result[length(Result)] = ' ' then
      Delete(Result,Length(Result),1);
  end;

Procedure test_proximity_F(var x : single);
begin
  if SameValue(x,sin_30,Tol) then
    x:=sin_30
    else
      if SameValue(x,cos_30,Tol) then
        x := cos_30
        else
          if SameValue(x,sin_60,Tol) then
            x := sin_60
            else
              if SameValue(x,cos_60,Tol) then
                x := cos_60
                else
                  if SameValue(x,sin_90,Tol) then
                    x := sin_90
                    else
                      if SameValue(x,cos_90,Tol) then
                        x := cos_90
                        else
                          if SameValue(x,sin_120,Tol) then
                            x := sin_120
                            else
                              if SameValue(x,cos_120,Tol) then
                                x := cos_120;
end;

Procedure test_proximity_A(var x : single);
begin

  if SameValue(x,120.0,toll) then
    x := 120
    else
      if SameValue(x,90.0,toll) then
        x := 90
        else
          if SameValue(x,60.0,toll) then
            x := 60
            else
              if SameValue(x,30.0,toll) then
                x := 30
                else
                  if SameValue(x,0.0,toll) then
                    x := 0
  else
    if SameValue(x,INT(x),Toll) then
      x := Int(x);
end;

procedure Draw_CentreMark(Pos:TPoint; Col:TColor; PW:byte; Sz:byte);
var
  X1,X2,Y1,Y2 : SmallInt;
  L, L1 : byte;
begin
  L  := trunc(Sz*1.2);
  L1 := Sz DIV 2;
  X1 := Pos.X-L1;       // Bounding box for centre Circle
  Y1 := Pos.Y-L1;
  X2 := Pos.X+L1;
  Y2 := Pos.Y+L1;
  with TriangleSolution.Display.Canvas do
    begin
      Pen.Width   := 0;
      Pen.Color   := clBlack;
      Brush.Color := Col;

      Ellipse(X1,Y1,X2,Y2);      // Draw centre circle
      Pen.Width := PW;

      X1 := Pos.X-L;
      Y1 := Y1+L1;               // Draw black Horiz Line
      MoveTo(X1,Y1);
      Y2 := Y1;
      X2 := Pos.X+L;
      LineTo(X2,Y2);

      X1 := Pos.X;               // draw black vert line
      Y1 := Pos.Y-L;
      MoveTo(X1,Y1);
      X2 := X1;
      Y2 := Pos.Y+L;
      LineTo(X2,Y2);

      Pen.Color := clWhite;

      X1 := Pos.X-L1;           // draw white horiz line across circle
      Y1 := Pos.y;
      MoveTo(x1,Y1);
      X2 := Pos.X+L1;
      Y2 := Y1;
      LineTo(X2,Y2);

      X1 := Pos.X;             // draw white vert line across circle
      Y1 := Pos.Y-L1;
      MoveTo(X1,Y1);
      X2 := X1;
      Y2 := Pos.Y+L1;
      LineTo(X2,Y2);

      Brush.Color := TriangleSolution.Display.Color;   //    clSkyBlue;
  end;
end;

procedure Draw_Display_Rules;
var
  L  : byte;
  x,
  y  : word;

begin
  with TriangleSolution.Display.Canvas do
    begin
      Pen.Width:=1;
      Pen.Color:=clBlack;
      font.Size:=6;
      font.Bold:=false;
      L := 5;
      y := 600;
      x := 0;
      while x < 600 do
        begin
          inc(x,5);
          MoveTo(x,y);
          if X mod 50 = 0 then
            lineTo(x,Y-(L*2))
          else
            LineTo(x,Y-L);
        end;
      y := 0;
      x := 2;
      While y < 600 do
        begin
          inc(y,5);
          MoveTo(x,y);
          if Y mod 50 = 0 then
            lineTo(x+L*2,Y)
          else
            LineTo(x+L,Y);

        end;
    end;

end;

procedure Draw_Dashed_Line(Start,Finish : TPoint;        // not yet used -  too many potential options for heights 2 & 3
                           L1,L2 : byte;
                           Col : TColor;
                           Wid : byte;
                           Psi : Single);
var
  X,X1,
  Y,Y1,Y2     : word;
  Pos1,
  Pos2  : TPoint;
begin
  SCT(Psi,'P');
  Y2 := Start.Y-Finish.Y;
  X  := trunc(L1*cos_p);
  Y  := trunc(L1*sin_p);
  X1 := trunc(L2*cos_p);
  Y1 := trunc(L2*sin_p);
  Pos1   := Start;
  Pos2.X := Start.X+X;
  Pos2.Y := Start.Y-Y;
  with TriangleSolution.Display.Canvas do
    begin
      Pen.Width := Wid;
      Pen.Color := col;
      MoveTo(Pos1); LineTo(Pos2);
      while Pos1.X < Finish.X-X1 do
        begin
          Pos1.X := Pos1.X+X1;
          Pos1.Y := Pos1.Y-Y1;
          Pos2.X := Pos1.X+X;
          Pos2.Y := Pos1.Y-Y;
          MoveTo(Pos1); LineTo(Pos2);
        end;
      Pos1.X := Pos1.X+X1;
      Pos1.Y := Pos1.Y-Y1;
      MoveTo(Pos1); LineTo(Finish);

      Font.Orientation:= trunc(Psi*10);
      TextOut(Finish.X+X,Finish.Y-Y1,#60+'--- H2');
    end;
end;

procedure Draw_Image;
var
  Y_Offset   : word;
  X_Offset   : byte;

  origin,P1,P2,          // Triangle vertices
  P4,                    // Height
  P8,P9,                 // Dimension Line points
  S1,
  S2,S3,                 // Sides
  InCirc,
  ExCirc          : Tpoint;


  H,H1,H2,H3,H4,H5,H6,H7,H8,
  W,W1,W2,W3,W4,W5,W6,W7,W8,
  M,N,D,E      : word;

  X1,X2,X3,
  Y1,Y2,Y3     : SmallInt;

  HP,Rad       : single;
  R,R1         : word;

  TOS          : word;       //  Type - Orient - Style   Number

  In_Offset_X,
  In_Offset_Y,
  Cr_Offset_X,
  Cr_Offset_Y  : Single;

  procedure Calc_Circle_Dias;
  begin
    HP       := Peri / 2;
    Rad      := Sqrt((HP-A)*(HP-B)*(HP-C) / HP);
    Insc_Dia := Rad*2;
    Insc_Rad := Rad;

    case TT of
      1 : begin     //  Right
            Circ_Dia    := mx;
            Circ_Rad    := Circ_Dia  / 2;
            Cr_Offset_X := TriWidth  / 2;
            Cr_Offset_Y := TriHeight / 2;
            case Orient of            // Offset from ORIGIN
              1 : begin
                    In_Offset_X := Rad;
                    In_Offset_Y := Rad;
                  end;
              2 : begin
                    In_Offset_X := S_Dims[2].Size - Rad;
                    In_Offset_Y := Rad;
                  end;
              3 : begin
                    In_Offset_X := Rad;
                    In_Offset_Y := S_Dims[3].Size - Rad;
                  end;
            end;
          end;
      2,
      6 : begin     // Scalene or Acute
            Circ_Dia    := A / Sin_a;
            Circ_Rad    := Circ_Dia / 2;
            In_Offset_X := Rad / Tan_a1;
            In_Offset_Y := Rad;
            Cr_Offset_X := B / 2;
            Cr_Offset_y := Sqrt(Circ_Rad * Circ_Rad - (B * B / 4));
          end;
      3 : begin     //  Equilateral
            Circ_Rad    := A / Root_3;
            Circ_Dia    := Circ_Rad * 2;
            In_Offset_X := B / 2;
            In_Offset_Y := Rad;
            Cr_Offset_X := In_Offset_X;
            Cr_Offset_y := In_Offset_Y;
          end;
      4 : begin     //  Isosceles
            Circ_Dia := A / Sin_a;
            Circ_Rad := Circ_Dia / 2;

            case Orient of           // Offset from ORIGIN
              5 : begin
                    In_Offset_X := S_Dims[2].Size / 2;
                    In_Offset_Y := Rad;
                    Cr_Offset_X := In_Offset_X;
                    Cr_Offset_Y := S_Dims[4].Size - Circ_Rad;
                  end;
              6 : begin
                    In_Offset_X := 0;
                    In_Offset_Y := S_Dims[4].Size - Rad;
                    Cr_Offset_X := In_Offset_X;
                    Cr_Offset_Y := Circ_Rad;
                  end;
              7 : begin
                    In_Offset_X := Rad;
                    In_Offset_Y := S_Dims[3].Size / 2;
                    Cr_Offset_X := S_Dims[5].Size - Circ_Rad ;
                    Cr_Offset_Y := In_Offset_Y;
                  end;
            end;
          end;
      5 : begin     //  Obtuce
            Circ_Dia := A / Sin_a;
            Circ_Rad := Circ_Dia / 2;
            HP := Sqrt(Circ_Rad * Circ_Rad - ((B * B) / 4));
            case Orient of
              8 : begin
                    In_Offset_X := Rad/Tan_a1;
                    In_Offset_Y := Rad;

                    Cr_Offset_X := B/2;
                    Cr_Offset_Y := HP;
                  end;
              9 : begin
                    In_Offset_X := Rad/Tan_a1;
                    In_Offset_Y := Rad;

                    Cr_Offset_X := B/2;
                    Cr_Offset_Y := HP;
                  end;
             10 : begin
                    In_Offset_X := Rad/Tan_a1;
                    In_Offset_Y := Rad;

                    Cr_Offset_X := B/2;
                    Cr_Offset_Y := HP;
                  end;
            end;
          end;
      7 : begin     //  Right-Isosceles
            Circ_Dia := Mx;
            Circ_Rad := Circ_Dia / 2;

            In_Offset_X := Rad/Tan_a1;
            In_Offset_Y := Rad;

            Cr_Offset_X := B/2;
            Cr_Offset_Y := 0;
          end;
    end;


    with TriangleSolution do
      begin
        Val_CircDia.Caption := FTxt(Circ_Dia,Deci);
        Val_InscDia.Caption := FTxt(Insc_Dia,Deci);

        Val_CircRad.Caption := FTxt(Circ_Rad,Deci);
        Val_InscRad.Caption := FTxt(Insc_Rad,Deci);

        Val_Circ_X.Caption  := FTxt(Cr_Offset_X,Deci);
        Val_Circ_Y.Caption  := FTxt(Cr_Offset_Y,Deci);

        Val_Insc_X.Caption  := FTxt(In_Offset_X,Deci);
        Val_Insc_Y.Caption  := FTxt(In_Offset_Y,Deci);
      end;

    InCirc.X := Origin.X + trunc(In_Offset_X * Scale);
    InCirc.Y := Origin.Y - trunc(In_Offset_Y * Scale);

    ExCirc.X := Origin.X + trunc(Cr_Offset_X * Scale);

    if Orient = 10 then
      ExCirc.Y := Origin.Y + trunc(Cr_Offset_Y * Scale)
    else
      ExCirc.Y := Origin.Y - trunc(Cr_Offset_Y * Scale);

    Tri_Data.P3.X   := InCirc.X;
    Tri_Data.P4.X   := ExCirc.X;
    Tri_Data.P3.Y   := InCirc.Y;
    Tri_Data.P4.Y   := ExCirc.Y;

    Tri_Data.InCirc := Insc_Dia;
    Tri_Data.ExCirc := Circ_Dia;

  end;
  procedure Get_Text_Size(S : String);
  begin
    with TriangleSolution.Display.Canvas do
      begin
        Font.Size:=Txt_Size_1;
        Font.Bold:=true;
        HeightOfText := TextHeight(S);
        WidthOfText  := TextWidth(S);

        H  := trunc(HeightOfText);
        H1 := trunc(H*3);
        H2 := trunc(H*2);
        H3 := trunc(H*1.5);
        H4 := trunc(H*1.4);
        H5 := trunc(H*0.5);
        H6 := trunc(H*0.6);
        H7 := trunc(H*0.4);
        H8 := trunc(H*0.9);

        W  := WidthOfText;
        W1 := W + H;
        W2 := W  DIV 2;
        W3 := W1 DIV 2;
        W4 := W + H5;
        W5 := W + H2;
        W6 := W5 DIV 2;
        W7 := W + W;
      end;
  end;

  procedure Get_Delta;
  begin
    Delta := ABS(alp-gam)/2;
    SCT(Delta,'D');
  end;
  procedure Get_Theta(N : byte);
  begin
    Case N of
      1 : Theta := 180 - alp;
      2 : Theta := 180 - alp + Bet/2;
      3 : Theta := Abs(180-gam)+bet/2;
      4 : Theta := 180 - gam;
    end;
    SCT(Theta,'T');
  end;
  procedure String_Dims;
  begin
    S_Dims[1].Dim := FTxt(S_Dims[1].Size,Deci);
    S_Dims[2].Dim := FTxt(S_Dims[2].Size,Deci);
    S_Dims[3].Dim := FTxt(S_Dims[3].Size,Deci);
    S_Dims[4].Dim := FTxt(S_Dims[4].Size,Deci);
    S_Dims[5].Dim := FTxt(S_Dims[5].Size,Deci);

    A_Dims[1].Dim := FTxt(A_Dims[1].Size,Deci);
    A_Dims[2].Dim := FTxt(A_Dims[2].Size,Deci);
    A_Dims[3].Dim := FTxt(A_Dims[3].Size,Deci);
  end;
  procedure Get_Scale;
  begin
     S_Dims[1].Size := A;
     S_Dims[2].Size := B;
     S_Dims[3].Size := C;
     S_Dims[4].Size := TriHeight;
     S_Dims[5].Size := TriWidth;

     If TriWidth > TriHeight then
       Scale := 400 / TriWidth  * ScaleFactor
     else
       Scale := 400 / TriHeight * ScaleFactor;

     Tri_Data.Scale    := Scale;
     Tri_Data.S_Factor := ScaleFactor;

     S_Dims[1].Pix := trunc(S_Dims[1].Size * scale);
     S_Dims[2].Pix := trunc(S_Dims[2].Size * scale);
     S_Dims[3].Pix := trunc(S_Dims[3].Size * scale);
     S_Dims[4].Pix := trunc(S_Dims[4].Size * Scale);
     S_Dims[5].Pix := trunc(S_Dims[5].Size * Scale);

     String_Dims;
  end;
  procedure Draw_ExScribedCircle(Pos : TPoint; R : word);
  var
    X1,X2,Y1,Y2 : SmallInt;    // can be negative
  begin
    X1 := Pos.x-R;
    X2 := Pos.x+R;
    Y1 := Pos.Y-R;
    Y2 := Pos.Y+R;
    with TriangleSolution.Display.Canvas do
      begin
        Brush.Color := clSkyBlue;
        Pen.Width   := 2;
        Pen.Color   := clYellow;
        Ellipse(X1,Y1,X2,Y2);
      end;
  end;
  procedure Draw_InScribedCircle(Pos : TPoint; R : word);
  var
    X1,X2,Y1,Y2 : word;
  begin
    X1 := Pos.x-R;
    X2 := Pos.x+R;
    Y1 := Pos.Y-R;
    Y2 := Pos.Y+R;
    with TriangleSolution.Display.Canvas do
      begin
        Brush.Color := clSkyBlue;
        Pen.Width   := 2;
        Pen.Color   := clMaroon;
        Ellipse(X1,Y1,X2,Y2);
      end;
  end;

  procedure DrawRightAngle(Pos:TPoint);
  var
    V     : word;
    Txt   : String;
  begin
    with TriangleSolution.Display.Canvas do
      begin
        Pen.Width:=2;
        Pen.Color:=clGreen;
        Font.Size:=Txt_Size_1;
        font.Bold:=true;
        font.Orientation:=0;
        Txt := '90°';
        Get_Text_Size(Txt);
        V := W7;
        case Orient of
          1 : begin
                X1 := H5;
                Y1 := H3;
                If Bet < 8 then X1 := -W4;
                if Gam < 8 then Y1 := -H5;
                TextOut(Pos.X+X1,Pos.Y-Y1,Txt);
                if style = 2 then
                  begin
                    MoveTo(Pos.X+V,Pos.Y);
                    LineTo(Pos.X+V,Pos.Y-V);
                    LineTo(Pos.X,  Pos.Y-V);
                  end;
              end;
          2 : begin
                X1 := W4;
                Y1 := H3;
                If Alp < 8 then Y1 := -H5;
                if Bet < 8 then X1 := -H5;
                TextOut(Pos.X-X1,Pos.Y-Y1,Txt);
                if style = 2 then
                  begin
                    MoveTo(Pos.X-V,Pos.Y);
                    LineTo(Pos.X-V,Pos.Y-V);
                    LineTo(Pos.X,  Pos.Y-V);
                  end;
              end;
          3 : begin
                X1 := H5;
                Y1 := H5;
                If Alp < 8 then X1 := -W4;
                if Gam < 8 then Y1 := -H3;
                TextOut(Pos.X+X1,Pos.Y+Y1,Txt);
                if style = 2 then
                  begin
                    MoveTo(Pos.X+V,Pos.Y);
                    LineTo(Pos.X+V,Pos.Y+V);
                    LineTo(Pos.X,  Pos.Y+V);
                  end;
              end;
          5 : begin
                X1 := W2;
                Y1 := Trunc(W6*Tan_a);
                TextOut(Pos.X-X1,Pos.Y+Y1,Txt);
                MoveTo(Pos.X-Y1,Pos.Y+Y1);
                LineTo(Pos.X,Pos.Y+Y1+Y1);
                LineTo(Pos.X+Y1,Pos.Y+Y1);
              end;
        end;
      end;
  end;

//++++++++++++++++++++++++++++++++++++++++++++++++++

  procedure Write_Dim(Pos:TPoint; N : byte;TxT : String; Rot:Word);
  begin
    with TriangleSolution.Display.Canvas do
      begin
        Font.Orientation:=Rot;
        case N of
          1 : textOut(Pos.X-X3,Pos.Y-Y3,Txt);
          2 : textOut(Pos.X-X3,Pos.Y+Y3,Txt);
          3 : textOut(Pos.X+X3,Pos.Y-Y3,Txt);
          4 : textOut(Pos.X+X3,Pos.Y+Y3,Txt);
        end;
      end;

  end;

  procedure DrawAlp(Pos:TPoint;Sw:Single);
  var
    L,M : byte;
    Rot : SmallInt;
    Txt : String;
  begin
    Txt := FTxt(Alp,Deci) + '°';
    Get_Text_Size(Txt);

    with TriangleSolution.Display.Canvas do
      begin
        Pen.Width:=2;
        Pen.Color:=clGreen;
        Font.Size:=Txt_Size_1;
        font.Bold:=true;
        MoveTo(Pos);
        case TT of
          1 : begin
                Case Orient of
                  1 : begin
                        M := 0;
                        Case Style of
                          1 : begin
                                // Right Angle
                              end;
                          2 : begin
                              end;
                          3 : begin
                              end;
                        end;
                      end;
                  2 : begin
                        Case Style of
                          1 : begin
                                X3 := W4;
                                Y3 := H3;
                                Rot := 0;
                                M := 1;
                              end;
                          2 : begin
                                X1 := Trunc(H8 / Sin_a1);
                                X2 := Trunc(H4 * Sin_a1);
                                X3 := X1-X2;
                                Y3 := Trunc(H4 * cos_a1);
                                E  := trunc(H8 / tan_a1);
                                L  := E+W2;
                                AngleArc(Pos.x,Pos.y,L,0,Sw);
                                Rot := trunc(Alp/2)*10;
                                M := 3;
                              end;
                          3 : begin
                                X3 := H;
                                Y3 := H5;
                                Rot := 0;
                                M := 4;
                              end;
                        end;
                        Write_Dim(Pos,M,TxT,Rot);
                      end;
                  3 : begin
                        E := trunc(H8 / tan_a1);
                        Case Style of
                          1 : begin
                                X3 := trunc(H5 + H2*Tan_a);
                                Y3 := H2;
                                Rot := 0;
                                M := 3;
                              end;
                          2 : begin
                                X1 := Trunc(H7 * Cos_a1);
                                Y1 := Trunc(H8 / Sin_a1);
                                Y2 := Trunc(H7 * Sin_a1);
                                Y3 := Y1+Y2;
                                L := E+W2;
                                AngleArc(Pos.x,Pos.y,L,Gam,Sw);
                                Rot := trunc(90 - Alp/2)*10;
                                M := 3;
                              end;
                          3 : begin
                                X3 := H5;
                                Y3 := H5;
                                Rot := 0;
                                M := 4;
                              end;
                        end;
                        Write_Dim(Pos,M,TxT,Rot);
                      end;
                end;
              end;
          2,
          6 : begin      // Scalene or Acute
                X1 := trunc(H /sin_a1);
                X2 := trunc(H3*sin_a1);
                X3 := X1-X2;
                Y3 := trunc(H3*cos_a1);
                E  := trunc(H / Tan_a1);
                L  := W2+E;
                AngleArc(Pos.x,Pos.y,L,0,Sw);
                Rot := trunc((Alp / 2) * 10);
                M := 3;

                Write_Dim(Pos,M,TxT,Rot);

              end;
          3 : begin      // Equilateral
              end;
          4 : begin      // Isosceles
                Case Orient of
                  5 : begin
                        case style of
                          2,
                          3: begin
                               X1 := trunc(H8 / sin_a1);
                               X2 := trunc(H4 * Sin_a1);
                               X3 := X1-X2;
                               Y3 := trunc(H4 * Cos_a1);
                               E  := trunc(H8 / Tan_a1);
                               L  := W2+E;
                               AngleArc(Pos.x,Pos.y,L,0,Sw);
                               Rot := trunc((Alp / 2) * 10);
                               M := 3;
                             end;
                          4: begin
                               X3 := H2;
                               Y3 := H5;
                               L  := trunc(B/6 * Scale);
                               AngleArc(Pos.x,Pos.y,L,0,Sw);
                               Rot := 0;
                               M := 4;
                             end;
                        end;
                      end;
                  6 : begin
                        case style of
                          1: begin
                               X1 := trunc(H1 * Tan_a1);
                               X3 := X1 + H5;
                               Y3 := H1;
                               L  := Y3+Y3;
                               AngleArc(Pos.x,Pos.y,L,Gam,Sw);
                               Rot := 0;
                               M := 3;
                             end;
                          2: begin
                                X3 := H5;
                                Y3 := trunc(H8 / Tan_a1);
                                L  := Y3+W2;
                                AngleArc(Pos.x,Pos.y,L,Gam,Sw);
                                Rot := 900;
                                M := 1;
                             end;
                          3: begin
                                X3 := W2;
                                Y1 := trunc(W6 * Sin_b);
                                Y3 := Y1 + H;
                                L  := Y1+W2;
                                AngleArc(Pos.x,Pos.y,L,Gam,Sw);
                                Rot := 0;
                                M := 1;
                             end;
                          4: begin
                               X3 := W2;
                               Y3 := H5;
                               L  := trunc(B/6);
                               AngleArc(Pos.x,Pos.y,L,Gam+Alp,Sw);
                               Rot := 0;
                               M := 2;
                             end;
                        end;
                      end;
                  7 : begin
                        case style of
                          2,
                          3: begin
                               X3 := trunc(H7*Cos_a1);
                               Y1 := trunc(H8/Sin_a1);
                               Y2 := trunc(H7*Sin_a1);
                               Y3 := Y1 + Y2;
                               E  := trunc(H8 / Tan_a1);
                               L  := W2+E;
                               AngleArc(Pos.x,Pos.y,L,Gam/2,Sw);
                               Rot := trunc((90 - Alp/2) * 10);
                               M := 3;
                             end;
                        end;
                      end;
                end;
                Write_Dim(Pos,M,TxT,Rot);
              end;
          5 : begin      // Obtuce
                case Orient of
                  8 : begin
                        case style of
                          1 : begin
                                Theta := 180 - Alp;
                                SCT(Theta,'T');
                                X1 := W4;
                                X2 := trunc(H/tan_t);
                                if Alp > 160 then X2 := 0;
                                X3 := X1+X2;
                                Y3 := H;
                                L  := trunc(B/4 * Scale);
                                AngleArc(Pos.x,Pos.y,L,0,Sw);
                                Rot := 0;
                                if Alp > 150 then
                                  M := 2
                                else
                                  M := 1;
                              end;
                          2 : begin
                                D  := trunc(H3/tan_a1);
                                X1 := trunc(D *cos_a1);
                                X2 := trunc(H5*cos_a1);
                                X3 := X1-X2;
                                Y3 := trunc(H2*cos_a1);
                                L  := W2+D;
                                AngleArc(Pos.x,Pos.y,L,0,Sw);
                                Rot := trunc(Alp / 2 *10);
                                M := 3;
                              end;
                          3 : begin
                                X3 := 0;
                                Y3 := H7;
                                L  := trunc(C/4 * Scale);
                                AngleArc(Pos.x,Pos.y,L,0,Sw);
                                Rot := 0;
                                M := 2;
                              end;
                          4 : begin
                                X3 := W2;
                                Y3 := H7;
                                L  := trunc(B/4 * Scale);
                                AngleArc(Pos.x,Pos.y,L,0,Sw);
                                Rot := 0;
                                M := 2;
                              end;
                        end;
                      end;
                  9 : begin
                        case style of
                          1 : begin
                                X3 := W4;
                                Y3 := H3;
                                L  := trunc(B/4 * Scale);
                                AngleArc(Pos.x,Pos.y,L,0,Sw);
                                Rot := 0;
                                M := 1;
                              end;
                          2 : begin
                                X1 := trunc(H8/sin_a1);
                                X2 := trunc(H4*sin_a1);
                                X3 := X1-X2;
                                Y3 := trunc(H4*cos_a1);
                                D  := trunc(H8/tan_a1);
                                L  := W2+D;
                                AngleArc(Pos.x,Pos.y,L,0,Sw);
                                Rot := trunc(Alp / 2 *10);
                                M := 3;
                              end;
                          3 : begin
                                X3 := H;
                                Y1 := trunc(W1 * tan_a);
                                Y3 := H4+Y1;
                                L  := trunc(B/4 * Scale);
                                AngleArc(Pos.x,Pos.y,L,0,Sw);
                                Rot := 0;
                                M := 3;
                              end;
                          4 : begin
                                X3 := 0;
                                Y3 := H7;
                                L  := trunc(B/4 * Scale);
                                AngleArc(Pos.x,Pos.y,L,0,Sw);
                                Rot := 0;
                                M := 4;
                              end;
                        end;
                      end;
                 10 : begin
                        case style of
                          1,
                          4 : begin
                                X3 := H2;
                                Y3 := H7;
                                L  := trunc(B/8 * Scale);
                                AngleArc(Pos.x,Pos.y,L,0,Sw);
                                Rot := 0;
                                M := 4;
                              end;
                          2,
                          3 : begin
                                X1 := trunc(H8/sin_a1);
                                X2 := trunc(H4*sin_a1);
                                X3 := X1-X2;
                                Y3 := trunc(H4*cos_a1);
                                D  := trunc(H8/tan_a1);
                                L  := W2+D;
                                AngleArc(Pos.x,Pos.y,L,0,Sw);
                                Rot := trunc(Alp / 2 *10);;
                                M := 3;
                              end;
                        end;
                      end;
                end;
                Write_Dim(Pos,M,TxT,Rot);
              end;
          7 : begin      // Right-Isosceles
                X1 := trunc(H8 / Sin_a1);
                X2 := trunc(H4 * Sin_a1);
                X3 := X1-X2;
                Y3 := trunc(H4 * Cos_a1);
                E  := trunc(H8 / Tan_a1);
                L := W2+E;
                AngleArc(Pos.x,Pos.y,L,0,Sw);
                Rot := trunc((Alp / 2) * 10);
                M := 3;

                Write_Dim(Pos,M,TxT,Rot);
              end;
          end;

      end;
  end;

//++++++++++++++++++++++++++++++++++++++++++++++++++

  procedure DrawBet(Pos:TPoint; Sw:Single);
  var
    L,M : byte;
    Rot : SmallInt;
    Txt : String;
  begin
    Txt := FTxt(Bet,Deci) + '°';
    Get_Text_Size(Txt);

    with TriangleSolution.Display.Canvas do
      begin
        Pen.Width:=2;
        Pen.Color:=clGreen;
        Font.Size:=Txt_Size_1;
        font.Bold:=true;
        MoveTo(Pos);
        case TT of
          1 : begin
                Case Orient of
                  1 : begin
                        Case Style of
                          1 : begin
                                X3 := trunc(H5 + H1*Tan_b);
                                Y3 := H2;
                                Rot := 0;
                                M := 4;
                              end;
                          2 : begin
                                X3 := Trunc(H2 * cos_b1);
                                Y1 := Trunc(H4 / sin_b1);
                                Y2 := Trunc(H2 * Sin_b1);
                                Y3 := Y1-Y2;
                                E  := trunc(H4 / tan_b1);
                                L  := W2+E;
                                AngleArc(Pos.x,Pos.y,L,-90,Sw);
                                Rot := -trunc(90 - Bet/2)*10;
                                M := 4;
                              end;
                          3 : begin
                                X3 := H;
                                Y3 := H4;
                                Rot := 0;
                                M := 3;
                              end;
                        end;
                      end;
                  2 : begin
                        Case Style of
                          1 : begin
                                X3 := trunc(W4 + H1*Tan_b);
                                Y3 := H2;
                                Rot := 0;
                                M := 2;
                              end;
                          2 : begin
                                E  := trunc(H4 / tan_b1);
                                D  := W+E;
                                X1 := Trunc(D  * Sin_b1);
                                X2 := Trunc(H5 * cos_b1);
                                X3 := X1+X2;
                                Y1 := Trunc(D  * cos_b1);
                                Y2 := Trunc(H5 * Sin_b1);
                                Y3 := Y1-Y2;
                                L  := E+W2;
                                AngleArc(Pos.x,Pos.y,L,-90,-Sw);
                                Rot := trunc(90-Bet/2)*10;
                                M := 2;
                              end;
                          3 : begin
                                X3 := W1;
                                Y3 := H4;
                                Rot := 0;
                                M := 1;
                              end;
                        end;
                      end;
                end;
                Write_Dim(Pos,M,TxT,Rot);
              end;
          2,
          6 : begin
                Delta := ABS(Alp-Gam) / 2;
                SCT(Delta,'D');
                E  := trunc(W3 / Sin_b1);
                X1 := trunc(E * cos_a);
                X2 := trunc(H5 * cos_d);
                X3 := X1-X2;
                Y1 := trunc(E * sin_a);
                Y2 := trunc(H5 * sin_d);
                Y3 := Y1-Y2;
                L  := E + H5;
                AngleArc(Pos.x,Pos.y,L,180+Alp,Sw);
                Rot := trunc(Delta * 10);
                If style = 2 then
                  Rot := -Rot;
                Font.Orientation := Rot;
                TextOut(pos.X-X3,Pos.Y+Y3,Txt);
              end;
          3 : begin    // Equilateral
               X1 := W2;
               Y1 := trunc(W*3*Tan_30);
               L  := Y1+H5;
               AngleArc(Pos.x,Pos.y,L,240,Sw);
               Font.Orientation:=0;
               TextOut(Pos.X-X1,Pos.Y+Y1,TxT);
             end;
          4 : begin    // Isosceles
               case Orient of
                 5 : begin
                      case style of
                        1 : begin
                              X1 := H5;
                              X2 := Trunc(H1*tan_b1);
                              X3 := X1+X2;
                              Y3 := H2;
                              L  := H1+H1;
                              Rad:= 90+Bet/2;
                              AngleArc(Pos.x,Pos.y,L,-Rad,Sw);
                              Font.Orientation:=0;
                              TextOut(pos.X+X3,Pos.Y+Y3,Txt);
                            end;
                        2 : begin
                              X3 := H5;
                              Y1 := Trunc(H8 / Tan_b1);
                              Y2 := W;
                              Y3 := Y1+Y2;
                              L  := W2+Y1;
                              Rad:= 90+Bet/2;
                              AngleArc(Pos.x,Pos.y,L,-Rad,Sw);
                              Font.Orientation:=900;
                              TextOut(pos.X-X3,Pos.Y+Y3,Txt);
                            end;
                        3 : begin
                              X3 := W2;
                              Y3 := Trunc(W6 * Tan_a);
                              L  := trunc(Y1 / Sin_a);
                              Rad:= 90+Bet/2;
                              AngleArc(Pos.x,Pos.y,L,-Rad,Sw);
                              Font.Orientation:=0;
                              TextOut(pos.X-X3,Pos.Y+Y3,Txt);
                            end;
                        4 : begin
                              X3 := W2;
                              Y3 := H4;
                              L  := trunc(C/6 * scale);
                              Rad:= 90+Bet/2;
                              AngleArc(Pos.x,Pos.y,L,-Rad,Sw);
                              Font.Orientation:=0;
                              TextOut(pos.X-X3,Pos.Y-Y3,Txt);
                            end;
                      end;
                    end;
                 6 : begin
                       case style of
                         2,
                         3 : begin
                               X1 := Trunc(H8 / sin_b1);
                               X2 := Trunc(H7 / sin_b1);
                               X3 := X1;   // -X2;
                               Y3 := Trunc(H7 * Cos_b1);
                               E  := trunc(H4 / tan_b1);
                               L  := W2+E;
                               AngleArc(Pos.x,Pos.y,L,-Bet,Sw);
                               Rot := trunc(-Bet/2 * 10);
                               Font.Orientation:=Rot;
                               TextOut(pos.X+X3,Pos.Y+Y3,Txt);
                             end;
                         4 : begin
                               X3 := H2;
                               Y3 := H4;
                               Font.Orientation:=0;
                               TextOut(pos.X+X3,Pos.Y-Y3,Txt);
                             end;
                       end;
                     end;
                 7 : begin
                       case style of
                         1 : begin
                               X1 := trunc(H1 * tan_b1);
                               X3 := H5 + X1;
                               Y3 := H2;
                               Font.Orientation:=0;
                               TextOut(pos.X+X3,Pos.Y+Y3,Txt);
                             end;
                         4 : begin
                               X3 := H;
                               Y3 := H4;
                               Font.Orientation:=0;
                               TextOut(pos.X+X3,Pos.Y-Y3,Txt);
                             end;
                       end;
                     end;
               end;
             end;
          5 : begin        // Obtuce
                Delta := 180+Alp;
                case Orient of
                  8 : begin
                        case style of
                          1 : begin
                                X1 := trunc(H/tan_g);
                                X3 := X1+H5;
                                Y3 := 0;
                                L  := Trunc(A/6 * Scale);
                                AngleArc(Pos.x,Pos.y,L,Delta,Sw);
                                Font.Orientation:=0;
                                TextOut(pos.X+X3,Pos.Y+Y3,Txt);
                              end;
                          2 : begin
                                Theta := ABS(90-Alp)+Bet/2;
                                SCT(Theta,'T');
                                D  := trunc(H8 / tan_b1);
                                X1 := trunc(D  * sin_t);
                                X2 := trunc(H5 * cos_b1);
                                X3 := X1+X2;
                                Y1 := Trunc(D  * cos_t);
                                Y2 := trunc(H5 * sin_b1);
                                Y3 := Y1-Y2;
                                L  := W2+D;
                                AngleArc(Pos.x,Pos.y,L,Delta,Sw);
                                Font.Orientation:= trunc(-(90-Theta) * 10);
                                TextOut(pos.X+X3,Pos.Y+Y3,Txt);
                              end;
                          3 : begin
                                X3 := 0;
                                Y3 := H4;
                                L  := Trunc(C/6 * Scale);
                                AngleArc(Pos.x,Pos.y,L,Delta,Sw);
                                Font.Orientation:=0;
                                TextOut(pos.X+X3,Pos.Y-Y3,Txt);
                              end;
                          4 : begin
                                X3 := 0;
                                Y3 := H4;
                                L  := Trunc(C/6 * Scale);
                                AngleArc(Pos.x,Pos.y,L,Delta,Sw);
                                font.Orientation:= 0;
                                textOut(Pos.X+X3,Pos.Y-Y3,Txt);
                              end;
                        end;
                      end;
                  9 : begin
                        Delta := 180+Alp;
                         case style of
                           1 : begin
                                 X1 := Trunc(H / tan_a);
                                 X3 := X1+W4;
                                 Y3 := 0;
                                 L  := Trunc(B/6 * Scale);
                                 AngleArc(Pos.x,Pos.y,L,Delta,Sw);
                                 Font.Orientation:= 0;
                                 TextOut(pos.X-X3,Pos.Y+Y3,Txt);
                               end;
                           2 : begin
                                 Theta := ABS(90-Gam)+Bet/2;
                                 SCT(Theta,'T');
                                 E := trunc(H8 / tan_b1);
                                 D := W + E;
                                 X1 := Trunc(D  * sin_t);
                                 X2 := Trunc(H5 * cos_t);
                                 X3 := X1+X2;
                                 Y1 := trunc(D  * cos_t);
                                 Y2 := trunc(H5 * sin_t);
                                 Y3 := Y1-Y2;
                                 L  := E + W2;
                                 AngleArc(Pos.x,Pos.y,L,Delta,Sw);

                                 Rot := trunc((90 - Theta) * 10);
                                 Font.Orientation := Rot;
                                 TextOut(pos.X-X3,Pos.Y+Y3,Txt);
                               end;
                           3 : begin
                                 X3 := W1;
                                 Y3 := H4;
                                 L  := Trunc(B/6 * Scale);
                                 AngleArc(Pos.x,Pos.y,L,Delta,Sw);
                                 Font.Orientation:=0;
                                 TextOut(pos.X-X3,Pos.Y-Y3,Txt);
                               end;
                           4 : begin
                                 X3 := W;
                                 Y3 := H4;
                                 L  := Trunc(B/6 * Scale);
                                 AngleArc(Pos.x,Pos.y,L,Delta,Sw);
                                 font.Orientation:= 0;
                                 textOut(Pos.X-X3,Pos.Y-Y3,Txt);
                               end;
                         end;
                       end;
                 10 : begin
                        Delta := 180+Alp;
                        case style of
                          1,
                          4 : begin
                                X3 := W2;
                                Y3 := H4;
                                L  := Trunc((A+C)/8 * Scale);
                                AngleArc(Pos.x,Pos.y,L,Delta,Sw);
                                Font.Orientation:=0;
                                TextOut(pos.X-X3,Pos.Y-Y3,Txt);
                              end;
                          2,
                          3 : begin
                                Delta := Abs(Alp-Gam)/2;
                                SCT(Delta,'D');
                                D  := trunc(W6 / sin_b1);
                                X1 := trunc(D * cos_a);
                                X2 := trunc(H * cos_d);
                                X3 := X1-X2;
                                Y1 := trunc(D * sin_a);
                                Y2 := trunc(H * sin_d);
                                L  := D - H;
                                AngleArc(Pos.x,Pos.y,L,180+Alp,Sw);
                                if style = 2 then
                                  begin
                                    Y3 := Y1+Y2;
                                    Font.Orientation:= trunc(-Delta * 10);
                                  end
                                else
                                  begin
                                    Y3 := Y1-Y2;
                                    Font.Orientation:= trunc(Delta * 10);
                                  end;
                                TextOut(pos.X-X3,Pos.Y+Y3,Txt);
                              end;
                         end;
                       end;
              end;
       end;
        end;
      end;
  end;

//++++++++++++++++++++++++++++++++++++++++++++++++++

  procedure DrawGam(Pos:TPoint; Sw:Single);
  var
    L   : byte;
    Rot : SmallInt;
    Txt : String;

  begin
    Txt := FTxt(Gam,Deci) + '°';
    Get_Text_Size(Txt);

    with TriangleSolution.Display.Canvas do
      begin
        Brush.Color:=clSkyBlue;
        Pen.Width:=2;
        Pen.Color:=clGreen;
        Font.Size:=Txt_Size_1;
        font.Bold:=true;
        MoveTo(Pos);
        case TT of
          1 : begin           // Right
                Case Orient of
                  1 : begin
                        Case Style of
                          1 : begin
                                X1 := H5;
                                Y1 := H3;
                                Font.Orientation:=0;
                                TextOut(Pos.X+X1,Pos.Y-Y1,TxT);
                              end;
                          2 : begin
                                E  := trunc(H4 / tan_g1);
                                D  := W+E;
                                X1 := Trunc(D  * Cos_g1);
                                X2 := Trunc(H5 * Sin_g1);
                                Y1 := Trunc(D  * Sin_g1);
                                Y2 := Trunc(H5 * Cos_g1);
                                L  := W2+E;
                                AngleArc(Pos.x,Pos.y,L,90+Bet,Sw);
                                Rot := -trunc(Gam/2)*10;
                                Font.Orientation:= Rot;
                                TextOut(Pos.X-X1+X2,Pos.Y-Y1-Y2,Txt);
                              end;
                          3 : begin
                                X1 := W1;
                                Y1 := H5;
                                Font.Orientation:=0;
                                TextOut(pos.X-X1,Pos.Y+Y1,Txt);
                              end;
                        end;
                      end;
                  2 : begin
                      end;
                  3 : begin
                        Case Style of
                          1 : begin
                                X3 := H5;
                                Y3 := H5;
                                Font.Orientation:=0;
                                TextOut(Pos.X+X3,Pos.Y+Y3,TxT);
                              end;
                          2 : begin
                                E  := trunc(H4 / tan_g1);
                                D  := W+E;
                                X1 := Trunc(D  * Cos_g1);
                                X2 := Trunc(H5 * Sin_g1);
                                X3 := X1-X2;
                                Y1 := Trunc(D  * Sin_g1);
                                Y2 := Trunc(H5 * Cos_g1);
                                Y3 := Y1-Y2;
                                L  := E+W2;
                                AngleArc(Pos.x,Pos.y,L,180,Sw);
                                Rot := trunc(Gam/2)*10;
                                Font.Orientation:=Rot;
                                TextOut(Pos.X-X3,Pos.Y+Y3,Txt);
                              end;
                          3 : begin
                                X3 := W1;
                                Y3 := H4;
                                Font.Orientation:=0;
                                TextOut(pos.X-X3,Pos.Y-Y3,Txt);
                              end;
                        end;
                      end;
                end;
              end;
          2,
          6 : begin           // Scalene or Acute
                E  := trunc(H / tan_g1);
                D  := W + E;
                X1 := trunc(D * cos_g1);
                X2 := trunc(H5 * sin_g1);
                X3 := X1-X2;
                Y1 := trunc(D * sin_g1);
                Y2 := trunc(H5 * cos_g1);
                Y3 := Y1 + Y2;
                L  := E + W2;
                AngleArc(Pos.x,Pos.y,L,180-Gam,Sw);
                Rot := trunc(-Gam / 2 * 10);
                Font.Orientation:=Rot;
                TextOut(pos.X-X3,Pos.Y-Y3,Txt);
              end;
          3 : begin           // Equilateral
              end;
          4 : begin           // Isosceles
                Case Orient of
                  5 : begin
                        Case Style of
                          1 : begin
                                X3 := H5;
                                Y3 := H2;
                                Font.Orientation:=0;
                                TextOut(pos.X+X3,Pos.Y-Y3,Txt);
                              end;
                        end;
                      end;
                  6 : begin
                        Case Style of
                          1 : begin
                                X3 := H5;
                                Y3 := H;
                                Font.Orientation:=0;
                                TextOut(pos.X+X3,Pos.Y+Y3,Txt);
                              end;
                        end;
                      end;
                  7 : begin
                        Case Style of
                          1 : begin
                                X3 := H5;
                                Y3 := H5;
                                Font.Orientation:=0;
                                TextOut(pos.X+X3,Pos.Y-Y3,Txt);
                              end;
                          2 : begin
                                X1 := trunc(H8 / Tan_g1);
                                X3 := X1 + W;
                                Y3 := H5;
                                L  := X1+W2;
                                AngleArc(Pos.x,Pos.y,L,90+Bet,Sw);
                                Font.Orientation:=0;
                                TextOut(pos.X-X3,Pos.Y-Y3,Txt);
                              end;
                          3 : begin
                                X1 := trunc(W3 * Sin_b);
                                X3 := X1 + H;
                                Y3 := W2;
                                L  := trunc(X1 / Cos_g1) + H;
                                AngleArc(Pos.x,Pos.y,L,90+Bet,Sw);
                                Font.Orientation:=900;
                                TextOut(pos.X-X3,Pos.Y+Y3,Txt);
                              end;
                          4 : begin
                                X3 := W5;
                                Y1 := trunc(W5 * Sin_g1);
                                Y3 := Y1 + H4;
                                L  := W6+W2;
                                AngleArc(Pos.x,Pos.y,L,90+Bet,Sw);
                                Font.Orientation:=0;
                                TextOut(pos.X-X3,Pos.Y-Y3,Txt);
                              end;
                        end;
                      end;
                end;
              end;
          5 : begin           // Obtuce
                Case Orient of
                  8 : begin
                        Case Style of
                          1 : begin
                                X3 := 0;
                                Y3 := H2;
                                L := trunc(B/6 * Scale);
                                AngleArc(Pos.x,Pos.y,L,180-Gam,Sw);
                                Font.Orientation:=0;
                                TextOut(pos.X+X3,Pos.Y-Y3,Txt);
                              end;
                          2 : begin
                                E  := trunc(H8 / tan_g1);
                                D  := W + E;
                                X1 := trunc(D  * cos_g1);
                                X2 := trunc(H5 * sin_g1);
                                X3 := X1-X2;
                                Y1 := trunc(D  * sin_g1);
                                Y2 := trunc(H5 * cos_g1);
                                Y3 := Y1 + Y2;
                                L  := E + W2;
                                AngleArc(Pos.x,Pos.y,L,180-Gam,Sw);
                                Rot := trunc(-Gam / 2 * 10);
                                Font.Orientation:=Rot;
                                TextOut(pos.X-X3,Pos.Y-Y3,Txt);
                              end;
                          3 : begin
                                X3 := W5;
                                Y1 := trunc(W5 * tan_g);
                                Y3 := Y1 + H4;
                                L := trunc(B/6 * Scale);
                                AngleArc(Pos.x,Pos.y,L,180-Gam,Sw);
                                Font.Orientation:=0;
                                TextOut(pos.X-X3,Pos.Y-Y3,Txt);
                              end;
                          4 : begin
                                X3 := W;
                                Y3 := H7;
                                L := trunc(B/6 * Scale);
                                AngleArc(Pos.x,Pos.y,L,180-Gam,Sw);
                                font.Orientation:= 0;
                                textOut(Pos.X-X3,Pos.Y+Y3,Txt);
                              end;
                        end;
                      end;
                  9 : begin
                        Theta := 180 - Gam;
                        SCT(Theta, 'T');
                        Case Style of
                          1 : begin
                                X1 := trunc(H / tan_t);
                                X3 := H5+X1;
                                Y3 := H;
                                L := trunc(B/6 * Scale);
                                AngleArc(Pos.x,Pos.y,L,Theta,Sw);
                                Font.Orientation:=0;
                                TextOut(pos.X+X3,Pos.Y-Y3,Txt);
                              end;
                          2 : begin
                                E  := trunc(H8 / tan_g1);
                                D  := W + E;
                                X1 := trunc(D  * cos_g1);
                                X2 := trunc(H5 * cos_g1);
                                X3 := X1-X2;
                                Y1 := trunc(D  * sin_g1);
                                Y2 := trunc(H5 * cos_g1);
                                Y3 := Y1 + Y2;
                                L  := E + W2;
                                AngleArc(Pos.x,Pos.y,L,Theta,Sw);
                                Rot := trunc(-Gam / 2 * 10);
                                Font.Orientation:=Rot;
                                TextOut(pos.X-X3,Pos.Y-Y3,Txt);
                              end;
                          3 : begin
                                X3 := W;
                                Y3 := H7;
                                L  := W2;
                                AngleArc(Pos.x,Pos.y,L,Theta,Sw);
                                Font.Orientation:=0;
                                TextOut(pos.X-X3,Pos.Y+Y3,Txt);
                              end;
                          4 : begin
                                X3 := W2;
                                Y3 := H7;
                                L := trunc(B/6 * Scale);
                                AngleArc(Pos.x,Pos.y,L,Theta,Sw);
                                font.Orientation:= 0;
                                textOut(Pos.X-X3,Pos.Y+Y3,Txt);
                              end;
                        end;
                      end;
                 10 : begin
                        Delta := 180-Gam;
                        Case Style of
                          1,
                          4 : begin
                                X3 := W5;
                                Y3 := H7;
                                L  := Trunc(B/6 * Scale);
                                AngleArc(Pos.x,Pos.y,L,Delta,Sw);
                                Font.Orientation:=0;
                                TextOut(pos.X-X3,Pos.Y+Y3,Txt);
                              end;
                          2,
                          3 : begin
                                E  := trunc(H8 / tan_g1);
                                D  := W + E;
                                X1 := trunc(D  * cos_g1);
                                X2 := trunc(H5 * cos_g1);
                                X3 := X1-X2;
                                Y1 := trunc(D  * sin_g1);
                                Y2 := trunc(H5 * cos_g1);
                                Y3 := Y1 + Y2;
                                L  := E + W2;
                                AngleArc(Pos.x,Pos.y,L,180-Gam,Sw);
                                Rot := trunc(-Gam / 2 * 10);
                                Font.Orientation:=Rot;
                                TextOut(pos.X-X3,Pos.Y-Y3,Txt);
                              end;
                        end;
                      end;
                end;
              end;
        end;
      end;
  end;

//++++++++++++++++++++++++++++++++++++++++++++++++++

  procedure Show_Dimensions;
  var
    Txt   : String;
    InUse : Char;

      procedure Calc_Line_Offsets(Psi : Single);
      begin
        SCT(Psi,'P');
        X1 := trunc(H5*Cos_p);
        X2 := trunc(H3*Cos_p);
        X3 := trunc(H *Cos_p);
        Y1 := trunc(H5*Sin_p);
        Y2 := trunc(H3*Sin_p);
        Y3 := trunc(H *Sin_p);
      end;
      procedure Calc_Dim_Offsets(Psi : Single);
      begin
        SCT(Psi,'P');
        Case Orient of
          1 : begin
                X1 := trunc(W2*Sin_p);
                X2 := trunc(H2*Cos_p);
                X3 := X1-X2;
                Y1 := trunc(H2*Sin_p);
                Y2 := trunc(W2*Cos_p);
                Y3 := Y1+Y2;
              end;
          2 : begin
                X1 := trunc(W2*Cos_p);
                X2 := trunc(H2*Sin_p);
                X3 := X1+X2;
                Y1 := trunc(W2*Sin_p);
                Y2 := trunc(H2*Cos_p);
                Y3 := Y1-Y2;
              end;
          3 : begin
                X1 := trunc(W2*Sin_p);
                X2 := trunc(H *Cos_p);
                X3 := X2-X1;
                Y1 := trunc(W2*Cos_p);
                Y2 := trunc(H *Sin_p);
                Y3 := Y1+Y2;
              end;
          5 : begin
                X1 := trunc(W2*Sin_p1);
                X2 := trunc(H2*Cos_p1);
                X3 := X2-X1;
                Y1 := trunc(H2*Sin_p1);
                Y2 := trunc(W2*Cos_p1);
                Y3 := Y1+Y2;
              end;
          6 : begin
                X1 := trunc(W2*Sin_p1);  // Alp
                X2 := trunc(H *Cos_p1);
                X3 := X2-X1;
                Y1 := trunc(H *Sin_p1);
                Y2 := trunc(W2*Cos_p1);
                Y3 := Y1+Y2;
              end;
          7 : begin
                X1 := trunc(W2*Cos_p1);  // Gam
                X2 := trunc(H *Sin_p1);
                X3 := X1-X2;
                Y1 := trunc(H *Cos_p1);
                Y2 := trunc(W2*Sin_p1);
                Y3 := Y1+Y2;
              end;
          8 : begin
                If InUse = 'C' then
                  begin
                    X1 := trunc(W2*Cos_p);
                    X2 := trunc(H *Sin_p);
                    X3 := X1+X2;
                    Y1 := trunc(W2*Sin_p);
                    Y2 := trunc(H *Cos_p);
                    Y3 := Y1-Y2;
                  end
                else
                  begin
                    X1 := trunc(W2*Cos_p);
                    X2 := trunc(H2*Sin_p);
                    X3 := X2-X1;
                    Y1 := trunc(H2*Cos_p);
                    Y2 := trunc(W2*Sin_p);
                    Y3 := Y1+Y2;
                  end;
              end;
          9 : begin
                If InUse = 'C' then
                  begin
                    X1 := trunc(W2*Cos_p);
                    X2 := trunc(H2*Sin_p);
                    X3 := X1+X2;
                    Y1 := trunc(W2*Sin_p);
                    Y2 := trunc(H2*Cos_p);
                    Y3 := Y2-Y1;
                  end
                else
                  begin
                    X1 := trunc(W2*Cos_p);
                    X2 := trunc(H *Sin_p);
                    X3 := X2-X1;
                    Y1 := trunc(W2*Sin_p);
                    Y2 := trunc(H *Cos_p);
                    Y3 := Y1+Y2;
                  end;
              end;
          10 : begin
                If InUse = 'C' then
                  begin
                    X1 := trunc(W2*Cos_p);
                    X2 := trunc(H2*Sin_p);
                    X3 := X1+X2;
                    Y1 := trunc(H2*Cos_p);
                    Y2 := trunc(W2*Sin_p);
                    Y3 := Y1-Y2;
                  end
                else
                  begin
                     X1 := trunc(W2*Cos_p);
                     X2 := trunc(H2*Sin_p);
                     X3 := X2-X1;
                     Y1 := trunc(H2*Cos_p);
                     Y2 := trunc(W2*Sin_p);
                     Y3 := Y1+Y2;
                  end;
               end;
         11 : begin
                X1 := trunc(W2*Cos_p);  // Gam or Alp
                X2 := trunc(H2*Sin_p);
                if Psi = Gam then
                  X3 := X2-X1
                else
                  X3 := X1+X2;
                Y1 := trunc(H2*Cos_p);
                Y2 := trunc(W2*Sin_p);
                If Psi = Gam then
                  Y3 := Y1+Y2
                else
                  Y3 := Y2-Y1;
              end;
        end;
      end;

    procedure Draw_Line_A;
    begin
      InUse := 'A';
      with TriangleSolution.Display.Canvas do
        begin
          Brush.Color:=clSkyBlue;
          Pen.Width:=1;
          Pen.Color:=clFuchsia;
          Font.Size:=Txt_Size_2;
          font.Bold:=true;
          Case TT of
            1 : begin                 // Right
                  case Orient of
                    1 : begin
                          Calc_Line_Offsets(Bet);
                          P8.X := P1.X+X1;     // Limit
                          P8.Y := P1.Y-Y1;
                          P9.X := P1.X+X2;
                          P9.Y := P1.Y-Y2;
                          MoveTo(P8);LineTo(P9);

                          P8.X := P2.X+X1;     // Limit
                          P8.Y := P2.Y-Y1;
                          P9.X := P2.X+X2;
                          P9.Y := P2.Y-Y2;
                          MoveTo(P8);LineTo(P9);

                          P8.X := P1.X+X3;      // Line
                          P8.Y := P1.Y-Y3;
                          P9.X := P2.X+X3;
                          P9.Y := P2.Y-Y3;
                          MoveTo(P8);LineTo(P9);

                          M := trunc(C/2 * Scale);  // Dimension
                          N := trunc(B/2 * Scale);
                          Calc_Dim_Offsets(Bet);

                          P4.X := P2.X+N-X3;
                          P4.Y := P2.Y+M-Y3;
                          Font.Orientation:=trunc(-Gam*10);
                          TextOut(P4.X,P4.Y,Txt);
                        end;
                    2 : begin
                          P8.X := P1.X+H5;
                          P8.Y := P1.Y;
                          P9.X := P1.X+H3;
                          P9.Y := P1.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X+H5;
                          P8.Y := P2.Y;
                          P9.X := P2.X+H3;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P1.X+H;
                          P8.Y := P1.Y;
                          P9.X := P2.X+H;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);

                          M := trunc(A/2 * Scale);
                          P4.X := P1.X+H5;
                          P4.Y := P1.Y-M+W2;
                          Font.Orientation:=900;
                          TextOut(P4.X,P4.Y,Txt);
                        end;
                    3 : begin
                          P8.X := P2.X;
                          P8.Y := P2.Y-H5;
                          P9.X := P2.X;
                          P9.Y := P2.Y-H3;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P1.X;
                          P8.Y := P1.Y-H5;
                          P9.X := P1.X;
                          P9.Y := P1.Y-H3;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X;
                          P8.Y := P2.Y-H;
                          P9.X := P1.X;
                          P9.Y := P1.Y-H;
                          MoveTo(P8);LineTo(P9);

                          N := trunc(A/2 * Scale);
                          P4.X := P2.X+N-W2;
                          If W2>N then
                            P4.Y := P2.Y-H1
                          else
                            P4.Y := P2.Y-H3;
                          Font.Orientation:=0;
                          TextOut(P4.X,P4.Y,Txt);
                        end;
                  end;
                end;
            2,
            6 : begin    // Scalene or Acute
                  Calc_Line_Offsets(90-Gam);
                  P8.X := P1.X+X1;     // Limit
                  P8.Y := P1.Y-Y1;
                  P9.X := P1.X+X2;
                  P9.Y := P1.Y-Y2;
                  MoveTo(P8);LineTo(P9);

                  P8.X := P2.X+X1;     // Limit
                  P8.Y := P2.Y-Y1;
                  P9.X := P2.X+X2;
                  P9.Y := P2.Y-Y2;
                  MoveTo(P8);LineTo(P9);

                  P8.X := P1.X+X3;      // Line
                  P8.Y := P1.Y-Y3;
                  P9.X := P2.X+X3;
                  P9.Y := P2.Y-Y3;
                  MoveTo(P8);LineTo(P9);

                  M := trunc(TriHeight/2 * Scale);  // Dimension
                  N := trunc(M/tan_g);
                  Calc_Dim_Offsets(Gam);

                  P4.X := P1.X-N+X3;
                  P4.Y := P1.Y-M-Y3;
                  Font.Orientation:=trunc(-Gam*10);
                  TextOut(P4.X,P4.Y,Txt);
                end;
            4 : begin    // Isosceles
                  Case Orient of
                    5 : begin
                          Calc_Line_Offsets(Bet/2);
                          P8.X := P1.X+X1;     // Limit
                          P8.Y := P1.Y-Y1;
                          P9.X := P1.X+X2;
                          P9.Y := P1.Y-Y2;
                          MoveTo(P8);LineTo(P9);

                          P8.X := P2.X+X1;     // Limit
                          P8.Y := P2.Y-Y1;
                          P9.X := P2.X+X2;
                          P9.Y := P2.Y-Y2;
                          MoveTo(P8);LineTo(P9);

                          P8.X := P1.X+X3;      // Line
                          P8.Y := P1.Y-Y3;
                          P9.X := P2.X+X3;
                          P9.Y := P2.Y-Y3;
                          MoveTo(P8);LineTo(P9);

                          M := trunc(TriHeight/2 * Scale);  // Dimension
                          N := trunc(B/4 * Scale);
                          Calc_Dim_Offsets(Bet);

                          P4.X := P1.X-N+X3;
                          P4.Y := P1.Y-M-Y3;
                          Font.Orientation:=trunc(-Gam*10);
                          TextOut(P4.X,P4.Y,Txt);
                        end
                      else
                        begin
                          P8.X := P2.X;
                          P8.Y := P2.Y-H5;
                          P9.X := P2.X;
                          P9.Y := P2.Y-H3;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P1.X;
                          P8.Y := P1.Y-H5;
                          P9.X := P1.X;
                          P9.Y := P1.Y-H3;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X;
                          P8.Y := P2.Y-H;
                          P9.X := P1.X;
                          P9.Y := P1.Y-H;
                          MoveTo(P8);LineTo(P9);

                          N    := trunc(A/2 * Scale);
                          P4.X := P2.X+N-W2;
                          P4.Y := P2.Y-H2;
                          Font.Orientation := 0;
                          TextOut(P4.X,P4.Y,Txt);
                        end;
                    end;
                end;
            5 : begin    // Obtuce
                  Case Orient of
                    8 : begin
                          Calc_Line_Offsets(90-Gam);
                          P8.X := P1.X+X1;
                          P8.Y := P1.Y-Y1;
                          P9.X := P1.X+X2;
                          P9.Y := P1.Y-Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X+X1;
                          P8.Y := P2.Y-Y1;
                          P9.X := P2.X+X2;
                          P9.Y := P2.Y-Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P1.X+X3;
                          P8.Y := P1.Y-Y3;
                          P9.X := P2.X+X3;
                          P9.Y := P2.Y-Y3;
                          MoveTo(P8);LineTo(P9);

                          M    := trunc(TriHeight/2 * Scale);
                          N    := trunc(M / tan_g);
                          Calc_Dim_Offsets(Gam);
                          P4.X := P1.X-N+X3;
                          P4.Y := P1.Y-M-Y3;
                          Font.Orientation := trunc(-Gam * 10);
                        end;
                    9 : begin
                          Calc_Line_Offsets(Gam-90);
                          P8.X := P1.X+X1;     // Limit
                          P8.Y := P1.Y+Y1;
                          P9.X := P1.X+X2;
                          P9.Y := P1.Y+Y2;
                          MoveTo(P8);LineTo(P9);

                          P8.X := P2.X+X1;     // Limit
                          P8.Y := P2.Y+Y1;
                          P9.X := P2.X+X2;
                          P9.Y := P2.Y+Y2;
                          MoveTo(P8);LineTo(P9);

                          P8.X := P1.X+X3;      // Line
                          P8.Y := P1.Y+Y3;
                          P9.X := P2.X+X3;
                          P9.Y := P2.Y+Y3;
                          MoveTo(P8);LineTo(P9);

                          Theta := 180 - Gam;
                          SCT(Theta,'T');
                          M := trunc(TriHeight/2 * Scale);  // Dimension
                          N := trunc(M / tan_t);
                          Calc_Dim_Offsets(Theta);
                          P4.X := P1.X+N+X3;
                          P4.Y := P1.Y-M+Y3;
                          Font.Orientation:=trunc(Theta*10);
                        end;
                   10 : begin
                          Calc_Line_Offsets(90-Gam);
                          P8.X := P1.X+X1;
                          P8.Y := P1.Y-Y1;
                          P9.X := P1.X+X2;
                          P9.Y := P1.Y-Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X+X1;
                          P8.Y := P2.Y-Y1;
                          P9.X := P2.X+X2;
                          P9.Y := P2.Y-Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P1.X+X3;
                          P8.Y := P1.Y-Y3;
                          P9.X := P2.X+X3;
                          P9.Y := P2.Y-Y3;
                          MoveTo(P8);LineTo(P9);

                          M    := trunc(TriHeight/2 * Scale);
                          N    := trunc(M / tan_g);
                          Calc_Dim_Offsets(Gam);
                          P4.X := P1.X-N+X3;
                          P4.Y := P1.Y-M-Y3;
                          Font.Orientation := trunc(-Gam * 10);
                        end;
                  end;
                  TextOut(P4.X,P4.Y,Txt);
                end;
            7 : begin
                  Calc_Line_Offsets(Gam);
                  P8.X := P1.X+X1;     // Limit
                  P8.Y := P1.Y-Y1;
                  P9.X := P1.X+X2;
                  P9.Y := P1.Y-Y2;
                  MoveTo(P8);LineTo(P9);

                  P8.X := P2.X+X1;     // Limit
                  P8.Y := P2.Y-Y1;
                  P9.X := P2.X+X2;
                  P9.Y := P2.Y-Y2;
                  MoveTo(P8);LineTo(P9);

                  P8.X := P1.X+X3;      // Line
                  P8.Y := P1.Y-Y3;
                  P9.X := P2.X+X3;
                  P9.Y := P2.Y-Y3;
                  MoveTo(P8);LineTo(P9);

                  M := trunc(TriHeight/2 * Scale);  // Dimension
                  N := trunc(B/4 * Scale);
                  Calc_Dim_Offsets(Bet);

                  P4.X := P1.X-N+X3;
                  P4.Y := P1.Y-M-Y3;
                  Font.Orientation:=trunc(-Gam*10);
                  TextOut(P4.X,P4.Y,Txt);
                end;
          end;
        end;
    end;
    procedure Draw_Line_B;
    begin
      InUse := 'B';
      with TriangleSolution.Display.Canvas do
        begin
          Brush.Color:=clSkyBlue;
          Pen.Width:=1;
          Pen.Color:=clFuchsia;
          Font.Size:=Txt_Size_2;
          font.Bold:=true;
          Case TT of
            1 : begin            // Right
                  case Orient of
                    3 : begin
                          Calc_Line_Offsets(Alp);
                          P8.X := Origin.X+X1;
                          P8.Y := Origin.Y+Y1;
                          P9.X := Origin.X+X2;
                          P9.Y := Origin.Y+Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P1.X+X1;
                          P8.Y := P1.Y+Y1;
                          P9.X := P1.X+X2;
                          P9.Y := P1.Y+Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := Origin.X+X3;
                          P8.Y := Origin.Y+Y3;
                          P9.X := P1.X+X3;
                          P9.Y := P1.Y+Y3;
                          MoveTo(P8);LineTo(P9);

                          N    := trunc(A/2 * Scale);
                          M    := trunc(C/2 * Scale);
                          Calc_Dim_Offsets(Alp);

                          P4.X := Origin.X+N+X3;
                          P4.Y := Origin.Y-M+Y3;
                          Font.Orientation := trunc(Gam*10);
                          TextOut(P4.X,P4.Y,Txt);
                        end
                      else
                        begin
                          P8.X := Origin.X;
                          P8.Y := Origin.Y+H5;
                          P9.X := Origin.X;
                          P9.Y := Origin.Y+H3;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P1.X;
                          P8.Y := P1.Y+H5;
                          P9.X := P1.X;
                          P9.Y := P1.Y+H3;
                          MoveTo(P8);LineTo(P9);
                          P8.X := Origin.X;
                          P8.Y := Origin.Y+H;
                          P9.X := P1.X;
                          P9.Y := P1.Y+H;
                          MoveTo(P8);LineTo(P9);

                          N    := trunc(B/2 * Scale);
                          P4.X := Origin.X+N-W2;
                          P4.Y := Origin.Y+H5;
                          Font.Orientation := 0;
                          TextOut(P4.X,P4.Y,Txt);
                        end;
                  end;
                end;
            2,
            6 : begin     // Scalene or Acute
                  P8.X := Origin.X;
                  P8.Y := Origin.Y+H5;
                  P9.X := Origin.X;
                  P9.Y := Origin.Y+H3;
                  MoveTo(P8);LineTo(P9);
                  P8.X := P1.X;
                  P8.Y := P1.Y+H5;
                  P9.X := P1.X;
                  P9.Y := P1.Y+H3;
                  MoveTo(P8);LineTo(P9);
                  P8.X := Origin.X;
                  P8.Y := Origin.Y+H;
                  P9.X := P1.X;
                  P9.Y := P1.Y+H;
                  MoveTo(P8);LineTo(P9);

                  N    := trunc(B/2 * Scale);
                  P4.X := Origin.X+N-W2;
                  P4.Y := Origin.Y+H5;
                  Font.Orientation := 0;
                  TextOut(P4.X,P4.Y,Txt);
                end;
            3 : begin     // Equilateral      // Identical to TT 1 Ori 1 or 2
                  P8.X := Origin.X;
                  P8.Y := Origin.Y+H5;
                  P9.X := Origin.X;
                  P9.Y := Origin.Y+H3;
                  MoveTo(P8);LineTo(P9);
                  P8.X := P1.X;
                  P8.Y := P1.Y+H5;
                  P9.X := P1.X;
                  P9.Y := P1.Y+H3;
                  MoveTo(P8);LineTo(P9);
                  P8.X := Origin.X;
                  P8.Y := Origin.Y+H;
                  P9.X := P1.X;
                  P9.Y := P1.Y+H;
                  MoveTo(P8);LineTo(P9);

                  N    := trunc(B/2 * Scale);
                  P4.X := Origin.X+N-W2;
                  P4.Y := Origin.Y+H5;
                  Font.Orientation := 0;
                  TextOut(P4.X,P4.Y,Txt);
                end;
            4 : begin     // Isosceles
                  case Orient of
                    5 : begin
                          P8.X := Origin.X;
                          P8.Y := Origin.Y+H5;
                          P9.X := Origin.X;
                          P9.Y := Origin.Y+H3;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P1.X;
                          P8.Y := P1.Y+H5;
                          P9.X := P1.X;
                          P9.Y := P1.Y+H3;
                          MoveTo(P8);LineTo(P9);
                          P8.X := Origin.X;
                          P8.Y := Origin.Y+H;
                          P9.X := P1.X;
                          P9.Y := P1.Y+H;
                          MoveTo(P8);LineTo(P9);

                          N    := trunc(B/2 * Scale);
                          P4.X := Origin.X+N-W2;
                          P4.Y := Origin.Y+H5;
                          Font.Orientation := 0;
                          TextOut(P4.X,P4.Y,Txt);
                        end;
                    6 : begin
                          Calc_Line_Offsets(Alp/2);
                          P8.X := Origin.X+X1;
                          P8.Y := Origin.Y+Y1;
                          P9.X := Origin.X+X2;
                          P9.Y := Origin.Y+Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P1.X+X1;
                          P8.Y := P1.Y+Y1;
                          P9.X := P1.X+X2;
                          P9.Y := P1.Y+Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := Origin.X+X3;
                          P8.Y := Origin.Y+Y3;
                          P9.X := P1.X+X3;
                          P9.Y := P1.Y+Y3;
                          MoveTo(P8);LineTo(P9);

                          N    := trunc(A/4 * Scale);
                          M    := trunc(TriHeight/2 * Scale);
                          Calc_Dim_Offsets(Alp);

                          P4.X := Origin.X+N+X3;
                          P4.Y := Origin.Y-M+Y3;
                          Font.Orientation := trunc(Gam*10);
                          TextOut(P4.X,P4.Y,Txt);
                        end;
                    7 : begin
                          Calc_Line_Offsets(alp);
                          P8.X := Origin.X+X1;
                          P8.Y := Origin.Y+Y1;
                          P9.X := Origin.X+X2;
                          P9.Y := Origin.Y+Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P1.X+X1;
                          P8.Y := P1.Y+Y1;
                          P9.X := P1.X+X2;
                          P9.Y := P1.Y+Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := Origin.X+X3;
                          P8.Y := Origin.Y+Y3;
                          P9.X := P1.X+X3;
                          P9.Y := P1.Y+Y3;
                          MoveTo(P8);LineTo(P9);

                          N    := trunc(TriWidth/2 * Scale);
                          M    := trunc(C/4 * Scale);
                          Calc_Dim_Offsets(Gam);

                          P4.X := Origin.X+N-X3;
                          P4.Y := Origin.Y-M+Y3;
                          Font.Orientation := trunc(Gam/2*10);
                          TextOut(P4.X,P4.Y,Txt);
                        end;
                  end;
                end;
            5 : begin     // Obtuce
                  P8.X := Origin.X;
                  P8.Y := Origin.Y+H5;
                  P9.X := Origin.X;
                  P9.Y := Origin.Y+H3;
                  MoveTo(P8);LineTo(P9);
                  P8.X := P1.X;
                  P8.Y := P1.Y+H5;
                  P9.X := P1.X;
                  P9.Y := P1.Y+H3;
                  MoveTo(P8);LineTo(P9);
                  P8.X := Origin.X;
                  P8.Y := Origin.Y+H;
                  P9.X := P1.X;
                  P9.Y := P1.Y+H;
                  MoveTo(P8);LineTo(P9);

                  N    := trunc(B/2 * Scale);
                  P4.X := Origin.X+N-W2;
                  P4.Y := Origin.Y+H5;
                  Font.Orientation := 0;
                  TextOut(P4.X,P4.Y,Txt);
                end;
            7 : begin
                  P8.X := Origin.X;
                  P8.Y := Origin.Y+H5;
                  P9.X := Origin.X;
                  P9.Y := Origin.Y+H3;
                  MoveTo(P8);LineTo(P9);
                  P8.X := P1.X;
                  P8.Y := P1.Y+H5;
                  P9.X := P1.X;
                  P9.Y := P1.Y+H3;
                  MoveTo(P8);LineTo(P9);
                  P8.X := Origin.X;
                  P8.Y := Origin.Y+H;
                  P9.X := P1.X;
                  P9.Y := P1.Y+H;
                  MoveTo(P8);LineTo(P9);

                  N    := trunc(B/2 * Scale);
                  P4.X := Origin.X+N-W2;
                  P4.Y := Origin.Y+H5;
                  Font.Orientation := 0;
                  TextOut(P4.X,P4.Y,Txt);
                end;
          end;
        end;

    end;
    procedure Draw_Line_C;
    begin
      InUse := 'C';
      with TriangleSolution.Display.Canvas do
        begin
          Brush.Color:=clSkyBlue;
          Pen.Width:=1;
          Pen.Color:=clFuchsia;
          Font.Size:=Txt_Size_2;
          font.Bold:=true;
          Case TT of
            1 : begin    // Right
                  case Orient of
                    2 : begin
                          Calc_Line_Offsets(Bet);
                          P8.X := Origin.X-X1;
                          P8.Y := Origin.Y-Y1;
                          P9.X := Origin.X-X2;
                          P9.Y := Origin.Y-Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X-X1;
                          P8.Y := P2.Y-Y1;
                          P9.X := P2.X-X2;
                          P9.Y := P2.Y-Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := Origin.X-X3;
                          P8.Y := Origin.Y-Y3;
                          P9.X := P2.X-X3;
                          P9.Y := P2.Y-Y3;
                          MoveTo(P8);LineTo(P9);

                          N    := trunc(B/2 * Scale);
                          M    := trunc(A/2 * Scale);
                          Calc_Dim_Offsets(Alp);

                          P4.X := Origin.X+N-X3;
                          P4.Y := Origin.Y-M+Y3;
                          Font.Orientation := trunc(Alp*10);
                          TextOut(P4.X,P4.Y,Txt);
                        end
                    else
                        begin
                          P8.X := Origin.X-H5;
                          P8.Y := Origin.Y;
                          P9.X := Origin.X-H3;
                          P9.Y := Origin.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X-H5;
                          P8.Y := P2.Y;
                          P9.X := P2.X-H3;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := Origin.X-H;
                          P8.Y := Origin.Y;
                          P9.X := P2.X-H;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);

                          M    := trunc(C/2 * Scale);
                          P4.X := Origin.X-H2;
                          P4.Y := Origin.Y-M+W2;
                          Font.Orientation := 900;
                          TextOut(P4.X,P4.Y,Txt);
                        end;
                  end;
                end;
            2,
            6 : begin    // Scalene or Acute
                  Calc_Line_Offsets(90-Alp);
                  P8.X := Origin.X-X1;
                  P8.Y := Origin.Y-Y1;
                  P9.X := Origin.X-X2;
                  P9.Y := Origin.Y-Y2;
                  MoveTo(P8);LineTo(P9);
                  P8.X := P2.X-X1;
                  P8.Y := P2.Y-Y1;
                  P9.X := P2.X-X2;
                  P9.Y := P2.Y-Y2;
                  MoveTo(P8);LineTo(P9);
                  P8.X := Origin.X-X3;
                  P8.Y := Origin.Y-Y3;
                  P9.X := P2.X-X3;
                  P9.Y := P2.Y-Y3;
                  MoveTo(P8);LineTo(P9);

                  M    := trunc(TriHeight/2 * Scale);
                  N    := trunc(M / tan_a);
                  Calc_Dim_Offsets(Alp);

                  P4.X := Origin.X+N-X3;
                  P4.Y := Origin.Y-M+Y3;
                  Font.Orientation := trunc(Alp*10);
                  TextOut(P4.X,P4.Y,Txt);
                end;
            4 : begin    // Isosceles   Orient 7
                  P8.X := Origin.X-H5;
                  P8.Y := Origin.Y;
                  P9.X := Origin.X-H3;
                  P9.Y := Origin.Y;
                  MoveTo(P8);LineTo(P9);
                  P8.X := P2.X-H5;
                  P8.Y := P2.Y;
                  P9.X := P2.X-H3;
                  P9.Y := P2.Y;
                  MoveTo(P8);LineTo(P9);
                  P8.X := Origin.X-H;
                  P8.Y := Origin.Y;
                  P9.X := P2.X-H;
                  P9.Y := P2.Y;
                  MoveTo(P8);LineTo(P9);

                  M    := trunc(C/2 * Scale);
                  P4.X := Origin.X-H2;
                  P4.Y := Origin.Y-M+W2;
                  Font.Orientation := 900;
                  TextOut(P4.X,P4.Y,Txt);
                end;
            5 : begin    // Obtuce
                  Case Orient of
                    8 : begin
                          Theta := 180 - Alp;
                          SCT(Theta,'T');
                          Calc_Line_Offsets(90-Theta);
                          P8.X := Origin.X-X1;
                          P8.Y := Origin.Y+Y1;
                          P9.X := Origin.X-X2;
                          P9.Y := Origin.Y+Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X-X1;
                          P8.Y := P2.Y+Y1;
                          P9.X := P2.X-X2;
                          P9.Y := P2.Y+Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := Origin.X-X3;
                          P8.Y := Origin.Y+Y3;
                          P9.X := P2.X-X3;
                          P9.Y := P2.Y+Y3;
                          MoveTo(P8);LineTo(P9);

                          M    := trunc(TriHeight/2 * Scale);
                          N    := trunc(M / tan_t);
                          Calc_Dim_Offsets(Theta);

                          P4.X := Origin.X-N-X3;
                          P4.Y := Origin.Y-M-Y3;
                          Font.Orientation := trunc(-Theta*10);
                        end
                    else
                        begin
                          Calc_Line_Offsets(90-Alp);
                          P8.X := Origin.X-X1;
                          P8.Y := Origin.Y-Y1;
                          P9.X := Origin.X-X2;
                          P9.Y := Origin.Y-Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X-X1;
                          P8.Y := P2.Y-Y1;
                          P9.X := P2.X-X2;
                          P9.Y := P2.Y-Y2;
                          MoveTo(P8);LineTo(P9);
                          P8.X := Origin.X-X3;
                          P8.Y := Origin.Y-Y3;
                          P9.X := P2.X-X3;
                          P9.Y := P2.Y-Y3;
                          MoveTo(P8);LineTo(P9);

                          M    := trunc(TriHeight/2 * Scale);
                          N    := trunc(M / tan_a);
                          Calc_Dim_Offsets(Alp);

                          P4.X := Origin.X+N-X3;
                          P4.Y := Origin.Y-M-Y3;
                          Font.Orientation := trunc(Alp*10);
                        end;
                    end;
                  TextOut(P4.X,P4.Y,Txt);
                end;
            7 : begin
                end;
          end;
        end;
    end;
    procedure Draw_Line_D;       // Height
    begin
      InUse := 'D';
      with TriangleSolution.Display.Canvas do
        begin
          Brush.Color:=clSkyBlue;
          Pen.Width:=1;
          Pen.Color:=clFuchsia;
          Font.Size:=Txt_Size_2;
          font.Bold:=true;
          Case TT of
            2,
            6 : begin  // Scalene or Acute
                  case style of
                    1 : begin
                          P8.X := P1.X+H5;
                          P8.Y := P1.Y;
                          P9.X := P1.X+H3;
                          P9.Y := P1.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X+H5;
                          P8.Y := P2.Y;
                          P9.X := P1.X+H3;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P1.X+H;
                          P8.Y := P1.Y;
                          P9.X := P1.X+H;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);
                          M    := trunc(TriHeight/2 * Scale);
                          P4.X := P1.X+H-W2;
                          P4.Y := P1.Y-M-H5;
                          Font.Orientation := 0;
                        end;
                    2 : begin
                          P8.X := Origin.X-H5;
                          P8.Y := Origin.Y;
                          P9.X := Origin.X-H3;
                          P9.Y := Origin.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X-H5;
                          P8.Y := P2.Y;
                          P9.X := Origin.X-H3;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := Origin.X-H;
                          P8.Y := Origin.Y;
                          P9.X := Origin.X-H;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);
                          M    := trunc(TriHeight/2 * Scale);
                          P4.X := Origin.X-H-W2;
                          P4.Y := Origin.Y-M-H5;
                          Font.Orientation := 0;
                        end;
                  end;
                  TextOut(P4.X,P4.Y,Txt);
                end;
            3 : begin  // Equilateral
                  P8.X := Origin.X-H5;
                  P8.Y := Origin.Y;
                  P9.X := Origin.X-H3;
                  P9.Y := Origin.Y;
                  MoveTo(P8);LineTo(P9);
                  P8.X := P2.X - H5;
                  P8.Y := P2.Y;
                  P9.X := Origin.X-H3;
                  P9.Y := P2.Y;
                  MoveTo(P8);LineTo(P9);
                  P8.X := Origin.X-H;
                  P8.Y := Origin.Y;
                  P9.X := Origin.X-H;
                  P9.Y := P2.Y;
                  MoveTo(P8);LineTo(P9);

                  M    := trunc(TriHeight/2 * Scale);
                  P4.X := Origin.X-H2;
                  P4.Y := Origin.Y-M+W2;
                  Font.Orientation := 900;
                  TextOut(P4.X,P4.Y,Txt);
                end;
            4 : begin  // Isosceles
                  case orient of
                    5 : begin
                          P8.X := Origin.X-H5;
                          P8.Y := Origin.Y;
                          P9.X := Origin.X-H3;
                          P9.Y := Origin.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X - H5;
                          P8.Y := P2.Y;
                          P9.X := Origin.X-H3;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := Origin.X-H;
                          P8.Y := Origin.Y;
                          P9.X := Origin.X-H;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);
                          M    := trunc(TriHeight/2 * Scale);
                          case style of
                            1,2 : P4.X := Origin.X-H2;
                            else  P4.X := Origin.X-W2-H;
                          end;
                        end;
                    6 : begin
                          P8.X := Origin.X-H5;
                          P8.Y := Origin.Y;
                          P9.X := P2.X-H3;
                          P9.Y := Origin.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X-H5;
                          P8.Y := P2.Y;
                          P9.X := P2.X-H3;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X-H;
                          P8.Y := Origin.Y;
                          P9.X := P2.X-H;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);
                          M    := trunc(TriHeight/2 * Scale);
                          Case style of
                            1,2 : P4.X := P2.X-H2;
                            else  P4.X := P2.X-W2-H;
                          end;
                        end;
                    end;
                  case Style of
                    1,
                    2 : begin
                          P4.Y := Origin.Y-M+W2;
                          Font.Orientation := 900;
                        end;
                    3,
                    4 : begin
                          P4.Y := Origin.Y-M-H5;
                          Font.Orientation := 0;
                        end;
                  end;
                  TextOut(P4.X,P4.Y,Txt);
                end;
            5 : begin  // Obtuce
                  case Orient of
                    8 : begin
                          P8.X := P1.X+H5;
                          P8.Y := P1.Y;
                          P9.X := P1.X+H3;
                          P9.Y := P1.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X+H5;
                          P8.Y := P2.Y;
                          P9.X := P1.X+H3;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P1.X+H;
                          P8.Y := P1.Y;
                          P9.X := P1.X+H;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);

                          M    := trunc(TriHeight / 2 * Scale);
                          P4.X := P1.X+H;
                          P4.Y := P1.Y-M+W2;
                          Font.Orientation := 900;
                        end;
                    9 : begin
                          P8.X := Origin.X-H5;
                          P8.Y := Origin.Y;
                          P9.X := Origin.X-H3;
                          P9.Y := Origin.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X-H5;
                          P8.Y := P2.Y;
                          P9.X := Origin.X-H3;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);
                          P8.X := Origin.X-H;
                          P8.Y := Origin.Y;
                          P9.X := Origin.X-H;
                          P9.Y := P2.Y;
                          MoveTo(P8);LineTo(P9);

                          M    := trunc(TriHeight / 2 * Scale);
                          P4.X := Origin.X-H2;
                          P4.Y := Origin.Y-M+W2;
                          Font.Orientation := 900;
                        end;
                   10 : begin
                          case style of
                            1,
                            2 : begin
                                  P8.X := Origin.X-H5;
                                  P8.Y := Origin.Y;
                                  P9.X := Origin.X-H3;
                                  P9.Y := Origin.Y;
                                  MoveTo(P8);LineTo(P9);
                                  P8.X := P2.X-H5;
                                  P8.Y := P2.Y;
                                  P9.X := Origin.X-H3;
                                  P9.Y := P2.Y;
                                  MoveTo(P8);LineTo(P9);
                                  P8.X := Origin.X-H;
                                  P8.Y := Origin.Y;
                                  P9.X := Origin.X-H;
                                  P9.Y := P2.Y;
                                  MoveTo(P8);LineTo(P9);

                                  M    := trunc(TriHeight / 2 * Scale);
                                  If Style = 1 then
                                    begin
                                      Font.Orientation := 0;
                                      P4.X := Origin.X-H-W2;
                                      P4.Y := Origin.Y-M-H5;
                                    end
                                  else
                                    begin
                                      Font.Orientation := 900;
                                      P4.X := Origin.X-H-H5;
                                      P4.Y := Origin.Y-M+W2;
                                    end;

                                end;
                            3,
                            4 : begin
                                  P8.X := P1.X+H5;
                                  P8.Y := P1.Y;
                                  P9.X := P1.X+H3;
                                  P9.Y := P1.Y;
                                  MoveTo(P8);LineTo(P9);
                                  P8.X := P2.X+H5;
                                  P8.Y := P2.Y;
                                  P9.X := P1.X+H3;
                                  P9.Y := P2.Y;
                                  MoveTo(P8);LineTo(P9);
                                  P8.X := P1.X+H;
                                  P8.Y := P1.Y;
                                  P9.X := P1.X+H;
                                  P9.Y := P2.Y;
                                  MoveTo(P8);LineTo(P9);

                                  M    := trunc(TriHeight / 2 * Scale);
                                  If Style = 4 then
                                    begin
                                      P4.X := P1.X+H-W2;
                                      P4.Y := P1.Y-M-H5;
                                      Font.Orientation := 0;
                                    end
                                  else
                                    begin
                                      P4.X := P1.X+H;
                                      P4.Y := P1.Y-M+W2;
                                      Font.Orientation := 900;
                                    end;
                                end;
                          end;
                        end;
                  end;
                  TextOut(P4.X,P4.Y,Txt);
                end;
            7 : begin  // Right-Isosceles
                  P8.X := Origin.X-H5;
                  P8.Y := Origin.Y;
                  P9.X := Origin.X-H3;
                  P9.Y := Origin.Y;
                  MoveTo(P8);LineTo(P9);
                  P8.X := P2.X-H5;
                  P8.Y := P2.Y;
                  P9.X := Origin.X-H3;
                  P9.Y := P2.Y;
                  MoveTo(P8);LineTo(P9);
                  P8.X := Origin.X-H;
                  P8.Y := Origin.Y;
                  P9.X := Origin.X-H;
                  P9.Y := P2.Y;
                  MoveTo(P8);LineTo(P9);
                  M    := trunc(TriHeight/2 * Scale);

                  P4.X := Origin.X-W2-H;
                  P4.Y := Origin.Y-M-H5;
                  Font.Orientation := 0;
                  TextOut(P4.X,P4.Y,Txt);
                end;
          end;
        end;
    end;
    procedure Draw_Line_E;       // Width
    begin
      InUse := 'E';
      with TriangleSolution.Display.Canvas do
        begin
          Brush.Color:=clSkyBlue;
          Pen.Width:=1;
          Pen.Color:=clFuchsia;
          Font.Size:=Txt_Size_2;
          font.Bold:=true;
          Case TT of
            4 : begin  // Isosceles   // Orient 7
                  P8.X := P2.X;
                  P8.Y := P2.Y-H5;
                  P9.X := P2.X;
                  P9.Y := P2.Y-H3;
                  MoveTo(P8);LineTo(P9);
                  P8.X := P1.X;
                  P8.Y := P1.Y-H5;
                  P9.X := P1.X;
                  P9.Y := P2.Y-H3;
                  MoveTo(P8);LineTo(P9);
                  P8.X := P2.X;
                  P8.Y := P2.Y-H;
                  P9.X := P1.X;
                  P9.Y := P2.Y-H;
                  MoveTo(P8);LineTo(P9);
                  N    := trunc(TriWidth/2 * Scale);
                  P4.X := P2.X+N-W2;
                  P4.Y := P2.Y-H2;
                  Font.Orientation := 0;
                  TextOut(P4.X,P4.Y,Txt);
                end;
            5 : begin  // Obtuce      // Orient 8 or 9
                  case Orient of
                    8 : begin
                          P8.X := P2.X;
                          P8.Y := P2.Y-H5;
                          P9.X := P2.X;
                          P9.Y := P2.Y-H1;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P1.X;
                          P8.Y := P1.Y-H5;
                          P9.X := P1.X;
                          P9.Y := P2.Y-H1;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X;
                          P8.Y := P2.Y-H2;
                          P9.X := P1.X;
                          P9.Y := P2.Y-H2;
                          MoveTo(P8);LineTo(P9);

                          N    := trunc(TriWidth  / 2 * Scale);
                          P4.X := P2.X+N-W2;
                          P4.Y := P2.Y-H1;
                          Font.Orientation := 0;
                          TextOut(P4.X,P4.Y,Txt);
                        end;
                    9 : begin
                          P8.X := Origin.X;
                          P8.Y := Origin.Y-H5;
                          P9.X := Origin.X;
                          P9.Y := P2.Y-H1;
                          MoveTo(P8);LineTo(P9);
                          P8.X := P2.X;
                          P8.Y := P2.Y-H5;
                          P9.X := P2.X;
                          P9.Y := P2.Y-H1;
                          MoveTo(P8);LineTo(P9);
                          P8.X := Origin.X;
                          P8.Y := P2.Y-H2;
                          P9.X := P2.X;
                          P9.Y := P2.Y-H2;
                          MoveTo(P8);LineTo(P9);

                          N    := trunc(TriWidth / 2 * Scale);
                          P4.X := Origin.X+N-W2;
                          P4.Y := P2.Y-H1;
                          Font.Orientation := 0;
                          TextOut(P4.X,P4.Y,Txt);
                        end;
                  end;
                end;
          end;
        end;
    end;

  begin
    Case TT of
      1 : begin    // Right
            TxT := S_Dims[1].Dim;
            Get_Text_Size(TxT);
            Draw_Line_A;

            TxT := S_Dims[2].Dim;
            Get_Text_Size(TxT);
            Draw_Line_B;

            TxT := S_Dims[3].Dim;
            Get_Text_Size(TxT);
            Draw_Line_C;
          end;
      2,
      6 : begin     // Scalene  or Acute
            Txt := S_Dims[1].Dim;    // A
            Get_Text_Size(TxT);
            Draw_Line_A;

            TxT := S_Dims[2].Dim;    // B
            Get_Text_Size(TxT);
            Draw_Line_B;

            TxT := S_Dims[3].Dim;    // C
            Get_Text_Size(TxT);
            Draw_Line_C;

            TxT := S_Dims[4].Dim;   // Height
            Get_Text_Size(TxT);
            Draw_Line_D;

          end;
      3 : begin     // Equilateral
            TxT := 'All Sides = '+S_Dims[2].Dim;   // Base (B)
            Get_Text_Size(TxT);
            Draw_Line_B;

            TxT := S_Dims[4].Dim;   // Height
            Get_Text_Size(TxT);
            Draw_Line_D;
          end;
      4 : begin     // Isosceles
            If Orient = 7 then
              begin
                TxT := S_Dims[2].Dim;   // B
                Get_Text_Size(TxT);
                Draw_Line_B;

                TxT := S_Dims[3].Dim;   // C
                Get_Text_Size(TxT);
                Draw_Line_C;

                TxT := S_Dims[5].Dim;   // Width
                Get_Text_Size(TxT);
                Draw_Line_E;
              end
            else
              begin
                TxT := S_Dims[1].Dim;   // A
                Get_Text_Size(TxT);
                Draw_Line_A;

                TxT := S_Dims[2].Dim;   // Base (B)
                Get_Text_Size(TxT);
                Draw_Line_B;

                TxT := S_Dims[4].Dim;   // Height
                Get_Text_Size(TxT);
                Draw_Line_D;
              end;
          end;
      5 : begin     // Obtuce
            Txt := S_Dims[1].Dim;    // A
            Get_Text_Size(TxT);
            Draw_Line_A;

            TxT := S_Dims[2].Dim;    // B
            Get_Text_Size(TxT);
            Draw_Line_B;

            TxT := S_Dims[3].Dim;    // C
            Get_Text_Size(TxT);
            Draw_Line_C;

            TxT := S_Dims[4].Dim;   // Height
            Get_Text_Size(TxT);
            Draw_Line_D;

            TxT := S_Dims[5].Dim;   // Width
            Get_Text_Size(TxT);
            Draw_Line_E;
          end;
      7 : begin     // Right-Isosceles
            TxT := S_Dims[1].Dim;   // A
            Get_Text_Size(TxT);
            Draw_Line_A;

            TxT := S_Dims[2].Dim;   // B
            Get_Text_Size(TxT);
            Draw_Line_B;

            TxT := S_Dims[4].Dim;   // Height
            Get_Text_Size(TxT);
            Draw_Line_D;
          end;
    end;
  end;

  procedure Draw_Line(Start,Finish:TPoint;Wid:byte;Col:TColor;TP:TPoint;S:String;R:word);
  begin
    with TriangleSolution.Display.Canvas do
      begin
        Pen.Color := Col;
        Pen.Width := Wid;
        MoveTo(Start);
        LineTo(Finish);
        Font.Orientation:=R;
        TextOut(TP.X,TP.Y,S);
      end;
  end;
  procedure Draw_Tri_Line(Start,Finish:TPoint;Wid:byte;Col:TColor);
  begin
    with TriangleSolution.Display.Canvas do
      begin
        Pen.Color := Col;
        Pen.Width := Wid;
        MoveTo(Start);
        LineTo(Finish);
      end;
  end;
  procedure Draw_Dim_Lines;

    procedure Draw_Height_Lines;
    var
      EndPos : TPoint;
    begin
      case TT of
        4 : begin
              Psi := 90-Gam;
              SCT(Psi,'P');
              EndPos.X := Origin.X+trunc(Height_2 * Scale * Cos_p);
              EndPos.Y := Origin.Y-trunc(Height_2 * Scale * Sin_p);
              Draw_Dashed_Line(Origin,EndPos,12,20,clLime,3,Psi);
            end;
      end;
    end;
    procedure Check_Angles;
    begin
      if Alp = Int(Alp) then
        begin
          if Bet = Int(Bet) then
            begin
              Gam := 180 - Alp - Bet;
              SCT(Gam,'G');
            end
          else
            if Gam = Int(Gam) then
              begin
                Bet := 180 - Alp - Gam;
                SCT(Bet,'B');
              end;
          end
        else
          If Bet = Int(Bet) then
            begin
              If Alp = Int(Alp) then
                begin
                  Gam := 180 - Bet - Alp;
                  SCT(Gam,'G');
                end
              else
                If Gam = Int(Gam) then
                  begin
                    Alp := 180 - Bet - Gam;
                    SCT(Alp,'A');
                  end;
            end
          else
            If Gam = Int(Gam) then
              begin
                If Alp = Int(Alp) then
                  begin
                    Bet := 180 - Gam - Alp;
                    SCT(Bet,'B');
                  end
                else
                  if Bet = Int(Bet) then
                    begin
                      Alp := 180 - Gam - Bet;
                      SCT(Alp,'A');
                    end;
              end;
    end;
  begin
    Check_Angles;
    case TT of
      1 : begin    // Right
            case Orient of
              1 : begin
                    DrawRightAngle(Origin);
                    DrawBet(P2,Bet);
                    DrawGam(P1,Gam);
                  end;
              2 : begin
                    DrawRightAngle(P1);
                    DrawAlp(Origin,Alp);
                    DrawBet(P2,Bet);
                  end;
              3 : begin
                    DrawRightAngle(P2);
                    DrawAlp(Origin,Alp);
                    DrawGam(P1,Gam);
                  end;
            end;
            Show_Dimensions;
          end;
      2,4,5,6 :
          begin    // Scalene - Acute - Isosceles - Obtuce
            DrawAlp(Origin,Alp);
            DrawBet(P2,Bet);
            DrawGam(P1,Gam);
            Show_Dimensions;
            // Draw_Height_Lines;
          end;
      3 : begin    // Equilateral
            DrawBet(P2,Bet);
            Show_Dimensions;
          end;
      7 : begin    // Right-Isosceles
            DrawRightAngle(P2);
            DrawAlp(Origin,Alp);
            Show_Dimensions;
          end;
    end;
  end;

  procedure Get_Style(O:byte);
  begin
    case O of
      1 : begin
            if Bet < 20 then Style := 1
            else
              if Gam < 20 then Style := 3
              else
                Style := 2;
          end;
      2 : begin
            if Bet < 20 then
              begin
                Style := 1;
                X_Offset := 180;
              end
            else
              if Alp < 20 then Style := 3
              else
                Style := 2;
          end;
      3 : begin
            if Alp < 20 then Style := 1
            else
              if Gam < 20 then Style := 3
              else
                Style := 2;
          end;
      4 : begin
            Style := 1;
          end;
      5 : begin
            if Bet < 20 then
              begin
                Style := 1;
                X_Offset := 180;
              end
            else
              if Gam < 20 then Style := 4
              else
                if Bet > 90 then Style := 3
                else
                  Style := 2;
          end;
      6 : begin
            if Alp < 20 then
              begin
                Style := 1;
                X_Offset := 180;
              end
            else
              if (Gam < 20) or (Bet < 20) then Style := 4
              else
                if Alp > 90 then Style := 3
                else
                  Style := 2;
          end;
      7 : begin
            if (Alp < 20) or (Bet < 20) then
              begin
                Style := 1;
                X_Offset := 180;
              end
            else
              if Gam < 20 then Style := 4
              else
                if Gam > 90 then Style := 3
                else
                  Style := 2;
          end;
      8 : begin
            if Bet+Gam <35 then Style := 4
            else
              if Bet < 20 then Style := 1
              else
                if Gam < 20 then Style := 3
                else
                    Style := 2;
          end;
      9 : begin
            if Alp+Bet <35 then Style := 4
            else
              if Bet < 20 then
                begin
                  Style := 1;
                  X_Offset := 180;
                end
              else
                if Alp < 20 then Style := 3
                else
                  Style := 2;
          end;
     10 : begin
            if Alp < 20 then Style := 1
            else
              if Gam < 20 then Style := 4
              else
                if A > C then Style := 3
                else
                  Style := 2;
          end;
     11 : begin
            if A > C then Style := 1
            else
              Style := 2;
          end;
    end;
    TOS := TT*100 + Orient * 10 + Style;
    TriangleSolution.TOS_Num.Caption:=IntToStr(TOS);
    Tri_Data.TOS:=TOS;
  end;

begin
  If UsingDisplay2 then
    begin
      X_Offset := 80;
      Y_Offset := 900;
    end
  else
    begin
      X_Offset := 80;
      Y_Offset := 500;
    end;

  Tri_Data.X_Offset:=X_Offset;
  Tri_Data.Y_Offset:=Y_Offset;

  Get_Scale;
    case TT of
      1 : begin                // Right
            Get_Style(Orient);   // also sets X_Offset for narrow images
            Origin.x := X_Offset;
            Origin.y := Y_offset;
            Case Orient of
              1 : begin
                    P1.x := Origin.x + S_Dims[2].Pix;
                    P1.y := Origin.Y;
                    P2.x := Origin.x;
                    P2.y := Origin.Y - S_Dims[3].Pix;

                    case Style of
                      1 : begin
                            S_Dims[1].Rot  := Trunc((Bet-90)*10);
                            S_Dims[2].Rot  := 0;
                            S_Dims[3].Rot  := 900;

                            A_Dims[1].Rot  := 0;
                            A_Dims[2].Rot  := 0;
                            A_Dims[3].Rot  := 0;

                          end;
                      2 : begin
                            S_Dims[1].Rot  := Trunc((Bet-90)*10);
                            S_Dims[2].Rot  := 0;
                            S_Dims[3].Rot  := 900;

                            A_Dims[1].Rot  := 0;
                            A_Dims[2].Rot  := trunc(((Bet / 2) - 90)*10);
                            A_Dims[3].Rot  := trunc((-Gam / 2) * 10);
                          end;
                      3 : begin
                            S_Dims[1].Rot  := Trunc(-Gam*10);
                            S_Dims[2].Rot  := 0;
                            S_Dims[3].Rot  := 0;

                            A_Dims[1].Rot  := 0;
                            A_Dims[2].Rot  := 0;
                            A_Dims[3].Rot  := 0;
                          end;
                    end;
                  end;
              2 : begin
                    P1.x := origin.X + S_Dims[2].Pix;
                    P1.y := origin.Y;
                    P2.x := P1.X;
                    P2.y := Origin.Y - S_Dims[1].Pix;
                    case Style of
                      1 : begin
                            S_Dims[1].Rot  := 900;
                            S_Dims[2].Rot  := 0;
                            S_Dims[3].Rot  := trunc(Alp * 10);

                            A_Dims[1].Rot  := 0;
                            A_Dims[2].Rot  := 0;
                            A_Dims[3].Rot  := 0;
                          end;
                      2 : begin
                            S_Dims[1].Rot  := 900;
                            S_Dims[2].Rot  := 0;
                            S_Dims[3].Rot  := trunc(Alp * 10);

                            A_Dims[1].Rot  := trunc((Alp / 2) * 10);
                            A_Dims[2].Rot  := Trunc((90 - (bet / 2)) * 10);
                            A_Dims[3].Rot  := 0;
                          end;
                      3 : begin
                            S_Dims[1].Rot  := 0;
                            S_Dims[2].Rot  := 0;
                            S_Dims[3].Rot  := trunc(Alp * 10);

                            A_Dims[1].Rot  := 0;
                            A_Dims[2].Rot  := 0;
                            A_Dims[3].Rot  := 0;
                          end;
                    end;
                  end;
              3 : begin
                    P1.x := Origin.X + S_Dims[1].Pix;
                    P1.y := Origin.Y - S_Dims[3].Pix;
                    P2.x := Origin.X;
                    P2.y := Origin.Y - S_Dims[3].Pix;
                    case Style of
                      1 : begin
                            S_Dims[1].Rot  := 0;
                            S_Dims[2].Rot  := trunc(Gam * 10);
                            S_Dims[3].Rot  := 900;

                            A_Dims[1].Rot  := 0;
                            A_Dims[2].Rot  := 0;
                            A_Dims[3].Rot  := 0;
                          end;
                      2 : begin
                            S_Dims[1].Rot  := 0;
                            S_Dims[2].Rot  := trunc(Gam / 2) * 10;
                            S_Dims[3].Rot  := 900;

                            A_Dims[1].Rot  := 900;
                            A_Dims[2].Rot  := 0;
                            A_Dims[3].Rot  := trunc(Gam / 2) * 10;
                          end;
                      3 : begin
                            S_Dims[1].Rot  := 0;
                            S_Dims[2].Rot  := trunc(Gam * 10);
                            S_Dims[3].Rot  := 0;

                            A_Dims[1].Rot  := 0;
                            A_Dims[2].Rot  := 0;
                            A_Dims[3].Rot  := 0;
                          end;
                    end;
                  end;
            end;

            S1.y := Y_Offset - S_Dims[2].pix div 2;
            S1.x := X_Offset + S_Dims[2].Pix div 2;
            S2.y := S1.y;
            S2.x := X_Offset + trunc(S_Dims[2].Pix);
            S3.y := Y_offset - trunc(S_Dims[3].pix / 2);
            S3.x := X_Offset - 10;

            If Peri = Trunc(Peri) then
              TriangleSolution.Pythag.show;
          end;
      2,
      6 : begin                // Scalene  or Acute
            Get_Style(Orient);
            Origin.x := X_Offset;
            Origin.y := Y_offset;
            P1.x := X_Offset + S_Dims[2].pix;
            P1.y := Y_Offset;
            P2.x := X_Offset + trunc(S_Dims[3].pix * Cos_a);
            P2.Y := Y_Offset - S_Dims[4].pix;      {height}
          end;
      3 : begin                // Equilateral
            Get_Style(Orient);
            Origin.x := X_Offset;
            Origin.y := Y_offset;
            P1.X:=X_Offset+S_Dims[2].Pix;
            P1.Y:=Y_Offset;
            P2.X:=X_Offset+(S_Dims[2].Pix div 2);
            P2.Y:=Y_Offset-S_Dims[4].Pix;          {height}
            // Show_Org_P1_P2;

          end;
      4 : begin                // Isosceles
            Get_Style(Orient);
            Origin.x := X_Offset;
            Origin.y := Y_offset;
            If A=B then        // Orient = 7
              begin
                P1.x := origin.x + S_Dims[5].Pix;       {width}
                P1.y := origin.Y - S_Dims[4].Pix div 2; {height}
                P2.x := Origin.x;
                P2.y := Origin.Y - S_Dims[4].Pix;
              end
            else
              If B=C then      // Orient = 6
                begin
                  Origin.X := X_offset + S_Dims[1].Pix DIV 2;
                  Origin.Y := Y_Offset;
                  P1.X := origin.X + S_Dims[1].Pix DIV 2;
                  P1.Y := Y_Offset - S_Dims[4].Pix;      {height}
                  P2.X := origin.X - S_Dims[1].Pix DIV 2;
                  P2.Y := P1.Y;
                end
              else
                begin          // Orient = 5
                  P1.x := origin.x + S_Dims[2].Pix;
                  P1.y := origin.Y;
                  P2.x := Origin.x + S_Dims[2].Pix div 2;
                  P2.y := Origin.Y - S_Dims[4].Pix;
                end;
          end;
      5 : begin                // Obtuce
            Get_Style(Orient);
            Origin.y := Y_offset;
            case Orient of
              8 : begin
                    P1.X := X_Offset + S_Dims[5].Pix;   {width}
                    Origin.X := P1.X - S_Dims[2].Pix;
                    P1.Y := Y_Offset;
                    P2.X := X_Offset;
                    P2.y := Y_offset - S_Dims[4].Pix;   {height}
                  end;
              9 : begin
                    Origin.x := X_Offset;
                    P1.x := X_Offset + S_Dims[2].Pix;
                    P1.y := Y_Offset;
                    P2.x := X_Offset + S_Dims[5].Pix;
                    P2.y := Y_Offset - S_Dims[4].Pix;
                  end;
             10 : begin
                    Origin.x := X_Offset;
                    P1.x := X_Offset + S_Dims[2].Pix;
                    P1.y := Y_Offset;
                    P2.x := X_Offset + trunc(S_Dims[3].Pix * Cos_a);
                    P2.y := Y_Offset - S_Dims[4].Pix;
                  end;
            end;
          end;
      7 : begin                // Right-Isosceles
            Get_Style(Orient);
            Origin.x := X_Offset;
            Origin.Y := Y_Offset;
            P1.x := X_Offset + S_Dims[2].Pix;
            P1.y := Y_Offset;
            P2.x := X_Offset + S_Dims[5].Pix DIV 2;
            P2.y := Y_Offset - S_Dims[4].Pix;
          end;
    end;

  Tri_Data.Org.X := Origin.X;
  Tri_Data.Org.Y := Origin.Y;
  Tri_Data.P1.X  := P1.X;
  Tri_Data.P1.Y  := P1.Y;
  Tri_Data.P2.X  := P2.X;
  Tri_Data.P2.Y  := P2.Y;


  Calc_Circle_Dias;

  R1 := trunc(Circ_Rad * Scale);
  Draw_ExScribedCircle(ExCirc,R1);

  Draw_Tri_Line(P1,P2,4,clRed);
  Draw_Tri_Line(Origin,P1,4,clGreen);
  Draw_Tri_Line(P2,Origin,4,clBlue);

  R := trunc(Rad*Scale);
  Draw_InscribedCircle(InCirc,R);

  Draw_CentreMark(InCirc,clRed,2,20);

  Draw_CentreMark(ExCirc,clBlue,2,20);

  Draw_Dim_Lines;

//  Draw_Display_Rules;

  TriangleSolution.Tri_type.text := tri_name[TT];
end;

procedure TTriangleSolution.AB_EqualClick(Sender: TObject);
begin
  Val_B.Caption:=Val_A.Caption;
  Val_B1.Caption:=Val_A1.Caption;
end;
procedure TTriangleSolution.BA_EqualClick(Sender: TObject);
begin
  Val_A.Caption:=Val_B.Caption;
  Val_A1.Caption:=Val_B1.Caption;
end;
procedure TTriangleSolution.AC_EqualClick(Sender: TObject);
begin
 Val_C.Caption  := Val_A.Caption;
 Val_C1.Caption := Val_A1.Caption;
end;
procedure TTriangleSolution.CA_EqualClick(Sender: TObject);
begin
  Val_A.Caption  := Val_C.Caption;
  Val_A1.Caption := Val_C1.Caption;
end;
procedure TTriangleSolution.BC_EqualClick(Sender: TObject);
begin
 Val_C.Caption :=Val_B.Caption;
 Val_C1.Caption:=Val_B1.Caption;
end;
procedure TTriangleSolution.CB_EqualClick(Sender: TObject);
begin
  Val_B.Caption :=Val_C.Caption;
  Val_B1.Caption:=Val_C1.Caption;
end;

procedure TTriangleSolution.AlpBet_EqualClick(Sender: TObject);
begin
 Val_Beta.Caption:=Val_Alpha.Caption;
 Val_Beta1.Caption:=Val_Alpha1.Caption;
end;
procedure TTriangleSolution.BetAlp_EqualClick(Sender: TObject);
begin
  Val_Alpha.Caption:=Val_Beta.Caption;
  Val_Alpha1.Caption:=Val_Beta1.Caption;
end;
procedure TTriangleSolution.BetGam_EqualClick(Sender: TObject);
begin
 Val_Gamma.Caption :=Val_Beta.Caption;
 Val_Gamma1.Caption:=Val_Beta1.Caption;
end;
procedure TTriangleSolution.GamBet_EqualClick(Sender: TObject);
begin
  Val_Beta.Caption :=Val_Gamma.Caption;
  Val_Beta1.Caption:=Val_Gamma1.Caption;
end;
procedure TTriangleSolution.AlpGam_EqualClick(Sender: TObject);
begin
 Val_Gamma.Caption:=Val_Alpha.Caption;
 Val_Gamma1.Caption:=Val_Alpha1.Caption;
end;
procedure TTriangleSolution.GamAlp_EqualClick(Sender: TObject);
begin
  Val_Alpha.Caption:=Val_Gamma.Caption;
  Val_Alpha1.Caption:=Val_Gamma1.Caption;
end;

procedure String_Angle(X : byte);
var s : String;
    p : byte;
    R : single;
    M_S : String;
  procedure ConvTo_MinSec(Deg:single;N:byte);
  var
    min : single;
    sec : single;
    D   : word;
    F   : single;
  begin
    D := trunc(Deg); // whole Degrees
    F := Deg - D;    // Decimal fraction of Defree
    min := f*60;     // Minutes as decimal
    M_S := IntToStr(trunc(min))+Chr(039)+'  ';
    sec := (min - trunc(min)) * 60;
    M_S := M_S + Copy(FloatToStr(sec),1,5) + '"';

    case N of
      1 : TriangleSolution.Alp_MinSec.Caption := M_S;
      2 : TriangleSolution.Bet_MinSec.Caption := M_S;
      3 : TriangleSolution.Gam_MinSec.Caption := M_S;
    end;
  end;
begin
  case X of
    1 : begin
          Str(alp:Totl:Deci,s);
          p := pos('.',s);
          TriangleSolution.Val_alpha.text :=Copy(s,1,p-1);
          TriangleSolution.Val_alpha1.text:=Copy(s,p+1,length(s));

          R := Rads(alp);
          Str(R:Totl:Deci,s);
          p := pos('.',s);
          TriangleSolution.Rad_alpha.text :=Copy(s,1,p-1);
          TriangleSolution.Rad_alpha1.text:=Copy(s,p+1,length(s));

          A_Dims[1].Size := alp;
          ConvTo_MinSec(alp,1);
        end;
    2 : begin
          Str(bet:Totl:Deci,s);
          p := pos('.',s);
          TriangleSolution.Val_beta.text :=Copy(s,1,p-1);
          TriangleSolution.Val_beta1.text:=Copy(s,p+1,length(s));
          R := Rads(bet);
          Str(R:Totl:Deci,s);
          p := pos('.',s);
          TriangleSolution.Rad_beta.text :=Copy(s,1,p-1);
          TriangleSolution.Rad_beta1.text:=Copy(s,p+1,length(s));
          A_Dims[2].Size := bet;
          ConvTo_MinSec(bet,2);
        end;
    3 : begin
          Str(gam:Totl:Deci,s);
          p := pos('.',s);
          TriangleSolution.Val_gamma.text :=Copy(s,1,p-1);
          TriangleSolution.Val_gamma1.text:=Copy(s,p+1,length(s));
          R := Rads(gam);
          Str(R:Totl:Deci,s);
          p := pos('.',s);
          TriangleSolution.Rad_gamma.text :=Copy(s,1,p-1);
          TriangleSolution.Rad_gamma1.text:=Copy(s,p+1,length(s));
          A_Dims[3].Size := gam;
          ConvTo_MinSec(gam,3);
        end;
  end;
end;

procedure Show_Txt_Size;
begin
  TriangleSolution.TxtSz_1.Caption:= IntToStr(Txt_Size_1);
  TriangleSolution.TxtSz_2.Caption:= IntToStr(Txt_Size_2);
end;

procedure TTriangleSolution.SolveClick(Sender: TObject);      // SOLVE
var
  x : byte;

  procedure Get_Orient;
  begin
    case tt of
      1 : begin          //  Right
            If alp = 90 then Orient := 1
            else
              If gam = 90 then Orient := 2
              else
                Orient := 3;
          end;
      2,
      6 : begin         //  Scalene or  acute
            Orient := 11;
          end;
      3 : begin         //  Equilateral
            Orient := 4;
          end;
      4 : begin         //  Isosceles
            if A=C then Orient := 5
            else
              if B=C then Orient := 6
              else
                Orient := 7;
          end;
      5 : begin         //  Obtuce
            If Mx=A then Orient := 8
              else
                if Mx=C then Orient := 9
                else
                  Orient := 10;
          end;
      7 : begin         //  Right-Isosceles
            Orient := 5;
          end;
    end;
    TriangleSolution.Orientation.Caption:=IntToStr(Orient);
  end;

  procedure Check_Type;
  begin
    TT := 0;
    if (A=B) and (B=C) then TT := 3             // Equilateral
    else
      if  (A=B) or (A=C) or (B=C) then TT := 4  // Isosceles
      else
        if (C>A) and (C>B) then TT := 5;        // Obtuce
  end;

  Procedure find_type;
    procedure Check_Scalene;
    begin
      if S_Count > 1 then TT := 2    // Scalene
        else TT := 6                 // acute
    end;
  begin

    if (alp=90) or (bet=90) or (gam=90) then TT := 1              // Right
    else
      if (A=B) and (B=C) then TT := 3                             // Equilateral
      else
        if  (A=B) or (A=C) or (B=C) then TT := 4                  // Isosceles
        else
          if (alp>90) or (bet>90) or (gam>90) then TT := 5        // Obtuce
          else
            Check_Scalene;

    if (TT=1) and (A=C) then TT := 7;                             // Right-Isosceles

    Tri_Data.TT := TT;

    Get_Orient;
  end;

  Procedure write_sides;
  var s : String;
      p : byte;
  begin
    Str(A:Totl:Deci,s);
    p := pos('.',s);
    Val_A.text := Copy(s,1,p-1);
    Val_A1.text:= Copy(s,p+1,length(s));

    Str(B:Totl:Deci,s);
    p := pos('.',s);
    Val_B.text := Copy(s,1,p-1);
    Val_B1.text:= Copy(s,p+1,length(s));


    Str(C:Totl:Deci,s);
    p := pos('.',s);
    Val_C.text := Copy(s,1,p-1);
    Val_C1.text:= Copy(s,p+1,length(s));
  end;

  Procedure write_angles;
  begin
    String_Angle(1);
    String_Angle(2);
    String_Angle(3);
  end;

  Procedure write_APH;
  var s : String;
  begin
    Str(Area:Totl:Deci,s);       Val_Area.text   := s;
    Str(Peri:Totl:Deci,s);       Val_Peri.text   := s;
    Str(Triheight:Totl:Deci,s);  Val_Height.Text := s;
    Str(TriWidth:Totl:Deci,s);   Val_Width.Text  := s;
    Done := true;
  end;

  procedure calc_known;
  begin
    known:=0;
    if num_data[1,1]>0 then inc(known,1);
    if num_data[2,1]>0 then inc(known,2);
    if num_data[3,1]>0 then inc(known,4);
    if known = 7 then exit;
    if num_data[1,2]>0 then inc(known,8);
    if num_data[2,2]>0 then inc(known,16);
    if num_data[3,2]>0 then inc(known,32);

  end;

  procedure CalcWidth_Height;
  begin
     Case TT of
       1 : begin        //  Right
             If alp = 90 then
               begin
                 TriWidth  := B;
                 TriHeight := C;
                 Height_2  := B*Sin_g;
                 Height_3  := B;
               end
             else
               if bet = 90 then
                 begin
                   TriWidth  := A;
                   TriHeight := C;
                   Height_2  := A*Sin_g;
                   Height_3  := A;
                 end
               else     // gam = 90
                 begin
                   TriWidth  := B;
                   TriHeight := A;
                   Height_2  := B*Sin_a;
                   Height_3  := B;
                 end;
           end;
       2,
       6 : begin        //  Scalene or  acute
             TriWidth  := B;
             TriHeight := A*Sin_g;
             Height_2  := B*Sin_g;
             Height_3  := A*Sin_b;
           end;
       3 : begin        //  Equilateral
             TriWidth  := A;
             TriHeight := A * Sin_g;
             Height_2  := TriHeight;
             Height_3  := TriHeight;
           end;
       4 : begin        //  Isosceles
             case Orient of
               5 : begin
                     TriHeight  := A * Sin_a;
                     TriWidth   := B;
                     Height_2   := B * Sin_a;
                     Height_3   := Height_2;
                    end;
               6 : begin
                     TriHeight  := B * Sin_g;
                     TriWidth   := A;
                     Height_2   := A * sin_g;
                     Height_3   := Height_2;
                   end;
               7 : begin
                     TriHeight  := C;
                     TriWidth   := B * Sin_a;
                     Height_2   := C * sin_a;
                     Height_3   := TriWidth;
                   end;
             end;
           end;
       5 : begin        //  Obtuce
             case Orient of
               8 : begin
                     TriHeight := A * Sin_g;
                     TriWidth  := A * Cos_g;
                     Height_2  := B * sin_g;
                     Height_3  := A * sin_b;
                   end;
               9 : begin
                     TriHeight := C * Sin_a;
                     TriWidth  := C * Cos_a;
                     Height_2  := B * sin_a;
                     Height_3  := B * sin_g;
                   end;
              10 : begin
                    TriHeight := C * Sin_a;
                    TriWidth  := B;
                    Height_2  := B * sin_g;
                    Height_3  := B * sin_a;
                   end;
             end;
           end;
       7 : begin        // Right-Isosceles
             TriHeight := A * Sin_g;
             TriWidth  := B;
             Height_2  := A;
             Height_3  := C;
           end;
     end;

    Val_Width.Caption    := Ftxt(TriWidth,Deci);
    Val_Height.Caption   := Ftxt(TriHeight,Deci);
    Val_Height_2.Caption := Ftxt(Height_2,Deci);
    Val_Height_3.Caption := Ftxt(Height_3,Deci);

    Tri_Data.W  := TriWidth;
    Tri_Data.H1 := TriHeight;
    Tri_Data.H2 := Height_2;
    Tri_Data.H3 := Height_3;
  end;

  procedure Get_Max_Angle(S:single; N:string);
  var
    T : Single;
  begin
    T := Degs(Arcsin(S));
    Message := 'Given side dimensions, Max '+N+' would be'+ FTxt(T,Deci)+'°';
    No_Sol.Show;
  end;
  procedure Find_third_angle(var x : single; a,b : real);
  begin
    x := 180 - a - b;
    test_proximity_A(x);
  end;
  Procedure Find_Alpha;
  begin
    sin_a := (A * sin_b) / B;
    if sin_a > 1 then
      begin
        Get_Max_Angle(B/A,'Beta');
        Bad := true;
        Exit;
      end;
    test_proximity_F(sin_a);
    alp := Degs(arcsin(sin_a));
    test_proximity_A(alp);
  end;
  Procedure Find_Gamma;
  begin
    if C=mx then
      begin
        cos_g := (A*A + B*B - C*C) /  (2*A*B) ;
        test_proximity_F(Cos_g);
        Gam := Degs(arccos(cos_g));
      end
    else
      begin
        sin_g := (C * sin_b) / B;
        test_proximity_F(sin_g);
        Gam := Degs(arcsin(sin_g));
      end;
    test_proximity_A(Gam);
    SCT(Gam,'G');
  end;
  procedure Find_Beta;
  begin
     sin_b := (B * sin_a) / A;
     if sin_b > 1 then
       begin
         if alp > 0 then
           Get_Max_Angle(A/B,'Alpha')
         else
           Get_Max_Angle(B/A,'Beta');
         Bad := true;
         Exit;
       end;
     test_proximity_F(sin_b);
     Bet := Degs(arcsin(sin_b));
     test_proximity_A(Bet);
  end;
  Procedure Find_A;
  begin
    if sin_b = 0 then
      begin
        A := b*b + c*c;
        A := A - (2*b*c * cos_a);
        A := Sqrt(A);
        D := Sqrt((b*b + c*c) - ((2*b*c) * cos_a))
      end
    else
      A := (B * sin_a) / sin_b;
  end;
  Procedure Find_B;
  begin
    B := (A * sin_b) / sin_a;
  end;
  Procedure Find_C;
  begin
    C := (A * sin_g) / sin_a;
  end;

  procedure solve_ABC;
  begin
    cos_b := (C*C + A*A - B*B) / (2 * C * A);

    test_proximity_F(cos_b);
    Bet := Degs(arccos(cos_b));
    SCT(Bet,'B');
    test_proximity_F(sin_b);
    test_proximity_F(cos_b);
    test_proximity_A(Bet);

    Find_Gamma;

    Alp := 180 - Bet-Gam;
    SCT(Alp,'A');
    test_proximity_F(sin_a);
    If Sin_a = 1 then Cos_a := 0;
    If Sin_a = 0 then Cos_a := 1;
    test_proximity_F(cos_a);

  end;

 // ------------------------------------------
  procedure solve_AB_alpha;
  begin
    sincos(Rads(alp),sin_a,cos_a);
    test_proximity_F(sin_a);
    If Sin_a = 1 then Cos_a := 0;
    If Sin_a = 0 then Cos_a := 1;
    test_proximity_F(cos_a);

    Find_Beta;
    If Bad then Exit;

    Find_Third_Angle(Gam,Bet,Alp);
    sincos(Rads(Gam),sin_g,cos_g);
    test_proximity_F(sin_g);
    If Sin_g = 1 then Cos_g := 0;
    If Sin_g = 0 then Cos_g := 1;
    test_proximity_F(cos_g);
    Find_C;
  end;
  procedure solve_AB_beta;
  begin
    sincos(Rads(bet),sin_b,cos_b);
    test_proximity_F(sin_b);
    If Sin_b = 1 then Cos_b := 0;
    If Sin_b = 0 then Cos_b := 1;
    test_proximity_F(cos_b);

    Find_Alpha;
    If Bad then Exit;

    Find_Third_Angle(Gam,Bet,Alp);
    sincos(Rads(gam),sin_g,cos_g);
    test_proximity_F(sin_g);
    If Sin_g = 1 then Cos_g := 0;
    If Sin_g = 0 then Cos_g := 1;
    test_proximity_F(cos_g);
    Find_C;
  end;
  procedure solve_AB_gamma;
  begin
    sincos(Rads(gam),sin_g,cos_g);
    test_proximity_F(sin_g);
    If Sin_g = 1 then Cos_g := 0;
    If Sin_g = 0 then Cos_g := 1;
    test_proximity_F(cos_g);
    tan_a := (A * sin_g) / (B - (A * cos_g));
    alp := Degs(arctan(tan_a));
    if alp < 0 then
      alp := 180 + alp;

    test_proximity_A(alp);
    sincos(Rads(alp),sin_a,cos_a);
    test_proximity_F(sin_a);
    If Sin_a = 1 then Cos_a := 0;
    If Sin_a = 0 then Cos_a := 1;
    test_proximity_F(cos_a);
    Find_Third_Angle(Bet,Gam,Alp);
    Find_C;
  end;

  // ------------------------------------------
  procedure solve_BC_alpha;
  begin
    SCT(Alp,'A');
//    sincos(Rads(alp),sin_a,cos_a);
    test_proximity_F(sin_a);
    If Sin_a = 1 then Cos_a := 0;
    test_proximity_F(cos_a);
    If C/B = cos_a then
      begin
        Bet := 90;
        Gam := 30;
        SCT(Bet,'B');
        SCT(Gam,'G');
        A := Sqrt(B*B + C*C);
        D := B;                // PECULIAR situation needs special attension
        B := A;
        A := D;
      end
    else
      begin
        Find_A;
    //    tan_b := (B * sin_a) / (C - (B * cos_a));
        cos_b := (C*C + A*A - B*B) / (2*C*A);
        bet := Degs(arccos(cos_b));
        if bet < 0 then
          bet := bet+180;
        test_proximity_A(bet);
        Find_third_angle(gam,alp,bet);
        SCT(Bet,'B');
        SCT(Gam,'G');
    //    sincos(Rads(bet),sin_b,cos_b);
        test_proximity_F(sin_b);
        If Sin_b = 1 then Cos_b := 0;
        If Sin_b = 0 then Cos_b := 1;
        test_proximity_F(cos_b);

    //    sincos(Rads(gam),sin_g,cos_g);
        test_proximity_F(sin_g);
        If Sin_g = 1 then Cos_g := 0;
        If Sin_g = 0 then Cos_g := 1;
        test_proximity_F(cos_g);

      end;
  end;
  procedure solve_BC_beta;
  begin
    sincos(Rads(bet),sin_b,cos_b);
    test_proximity_F(sin_b);
    If Sin_b = 1 then Cos_b := 0;
    If Sin_b = 0 then Cos_b := 1;
    test_proximity_F(cos_b);
    sin_g := (C * sin_b) / B;
    if sin_g > 1 then
      if sin_a > 1 then
        begin
          Get_Max_Angle(B/C,'Beta');
          Bad := true;
          Exit;
        end;

    test_proximity_F(sin_g);
    If Sin_g = 1 then Cos_g := 0;
    If Sin_g = 0 then Cos_g := 1;
    gam := Degs(arcsin(sin_g));
    test_proximity_A(gam);
    Find_third_angle(alp,bet,gam);
    sincos(Rads(alp),sin_a,cos_a);
    test_proximity_F(sin_a);
    If Sin_a = 1 then Cos_a := 0;
    If Sin_a = 0 then Cos_a := 1;
    test_proximity_F(cos_a);
    Find_A;
  end;
  procedure solve_BC_gamma;
  begin
    sincos(Rads(gam),sin_g,cos_g);
    test_proximity_F(sin_g);
    If Sin_g = 1 then Cos_g := 0;
    If Sin_g = 0 then Cos_g := 1;
    test_proximity_F(cos_g);
    sin_b := (B * sin_g) / C;
    if Sin_b > 1 then
      begin
        Get_Max_Angle(C/B,'Gamma');
        Bad := true;
        Exit;
      end;
    bet := Degs(arcsin(sin_b));
    test_proximity_A(bet);
    Find_third_angle(alp,bet,gam);
    sincos(Rads(alp),sin_a,cos_a);
    test_proximity_F(sin_a);
    If Sin_a = 1 then Cos_a := 0;
    If Sin_a = 0 then Cos_a := 1;
    test_proximity_F(cos_a);
    Find_A;
  end;

  // ------------------------------------------
  procedure solve_AC_alpha;
  begin
    sincos(rads(alp),sin_a,cos_a);
    test_proximity_F(sin_a);
    If Sin_a = 1 then Cos_a := 0;
    If Sin_a = 0 then Cos_a := 1;
    test_proximity_F(cos_a);
    sin_g := (C * sin_a) / A;
    If sin_g > 1 then
      begin
        Get_Max_Angle(C/A,'Alpha');
        Bad := true;
        Exit;
      end;
    test_proximity_F(sin_g);
    If Sin_a = 1 then Cos_a := 0;
    If Sin_a = 0 then Cos_a := 1;
    gam := Degs(arcsin(sin_g));
    test_proximity_A(gam);
    Find_third_angle(bet,gam,alp);
    sincos(rads(bet),sin_b,cos_b);
    test_proximity_F(sin_b);
    If Sin_b = 1 then Cos_b := 0;
    If Sin_a = 0 then Cos_a := 1;
    test_proximity_F(cos_b);
    Find_B;
  end;
  procedure solve_AC_beta;
  begin
    sincos(Rads(bet),sin_b,cos_b);
    test_proximity_F(sin_b);
    If Sin_b = 1 then Cos_b := 0;
    If Sin_b = 0 then Cos_b := 1;
    test_proximity_F(cos_b);
    tan_g := (C * sin_b) / (A - (C * cos_b));
    gam := Degs(arctan(tan_g));
    test_proximity_A(gam);
    Find_third_angle(alp,bet,gam);
    sincos(Rads(alp),sin_a,cos_a);
    test_proximity_F(sin_a);
    If Sin_a = 1 then Cos_a := 0;
    If Sin_a = 0 then Cos_a := 1;
    test_proximity_F(cos_a);
    Find_B;
    sincos(Rads(gam),sin_g,cos_g);
    test_proximity_F(sin_g);
    If Sin_g = 1 then Cos_g := 0;
    If Sin_g = 0 then Cos_g := 1;
    test_proximity_F(cos_g);
  end;
  procedure solve_AC_gamma;
  begin
    sincos(Rads(gam),sin_g,cos_g);
    test_proximity_F(sin_g);
    If Sin_g = 1 then Cos_g := 0;
    If Sin_g = 0 then Cos_g := 1;
    test_proximity_F(cos_g);
    sin_a := (A * sin_g) / C;
    if sin_a > 1 then
      begin
        Get_Max_Angle(C/A,'Gamma');
        Bad := true;
        Exit;
      end;
    test_proximity_F(sin_a);
    If Sin_a = 1 then Cos_a := 0;
    If Sin_a = 0 then Cos_a := 1;
    alp := Degs(arcsin(sin_a));
    test_proximity_F(alp);
    Find_third_angle(bet,alp,gam);
    sincos(Rads(bet),sin_b,cos_b);
    test_proximity_F(sin_b);
    If Sin_b = 1 then Cos_g := 0;
    If Sin_b = 0 then Cos_b := 1;
    test_proximity_F(cos_b);
    Find_B;
  end;

  // ------------------------------------------
  procedure solve_BC;
  begin
    sincos(Rads(alp),sin_a,cos_a);
    test_proximity_F(sin_a);
    If Sin_a = 1 then Cos_a := 0;
    If Sin_a = 0 then Cos_a := 1;
    test_proximity_F(cos_a);
    sincos(Rads(bet),sin_b,cos_b);
    test_proximity_F(sin_b);
    If Sin_b = 1 then Cos_b := 0;
    If Sin_b = 0 then Cos_b := 1;
    test_proximity_F(cos_b);
    sincos(Rads(gam),sin_g,cos_g);
    test_proximity_F(sin_g);
    If Sin_g = 1 then Cos_g := 0;
    If Sin_g = 0 then Cos_g := 1;
    test_proximity_F(cos_g);
    B := (A * sin_b) / sin_a;
    C := (A * sin_g) / sin_a;
  end;
  procedure solve_A_alpha_beta;
  begin
    Find_third_angle(gam,alp,bet);
    solve_BC;
  end;
  procedure solve_A_alpha_gamma;
  begin
    Find_third_angle(bet,alp,gam);
    solve_BC;
  end;
  procedure solve_A_beta_gamma;
  begin
    Find_third_angle(alp,bet,gam);
    solve_BC;
  end;

  // ------------------------------------------
  procedure solve_AC;
  begin
    sincos(Rads(alp),sin_a,cos_a);
    test_proximity_F(sin_a);
    If Sin_a = 1 then Cos_a := 0;
    If Sin_a = 0 then Cos_a := 1;
    test_proximity_F(cos_a);
    sincos(Rads(bet),sin_b,cos_b);
    test_proximity_F(sin_b);
    If Sin_b = 1 then Cos_b := 0;
    If Sin_b = 0 then Cos_b := 1;
    test_proximity_F(cos_b);
    sincos(Rads(gam),sin_g,cos_g);
    test_proximity_F(sin_g);
    If Sin_g = 1 then Cos_g := 0;
    If Sin_g = 0 then Cos_g := 1;
    test_proximity_F(cos_g);
    A := (B * sin_a) / sin_b;
    C := (A * sin_g) / sin_a;
  end;
  procedure solve_B_alpha_beta;
  begin
    Find_third_angle(gam,alp,bet);
    solve_AC;
  end;
  procedure solve_B_alpha_gamma;
  begin
    Find_third_angle(bet,alp,gam);
    solve_AC;
  end;
  procedure solve_B_beta_gamma;
  begin
    Find_third_angle(alp,bet,gam);
    solve_AC;
  end;

  // ------------------------------------------
  procedure solve_AB;
  begin
    sincos(Rads(alp),sin_a,cos_a);
    test_proximity_F(sin_a);
    If Sin_a = 1 then Cos_a := 0;
    If Sin_a = 0 then Cos_a := 1;
    test_proximity_F(cos_a);

    sincos(Rads(gam),sin_g,cos_g);
    test_proximity_F(sin_g);
    If Sin_g = 1 then Cos_g :=0;
    If Sin_g = 0 then Cos_g :=1;
    test_proximity_F(cos_g);

    sincos(Rads(bet),sin_b,cos_b);
    test_proximity_F(sin_b);
    If Sin_b = 1 then Cos_b := 0;
    If Sin_b = 0 then Cos_b := 1;
    test_proximity_F(cos_b);

    A := C * Sin_a / Sin_g;
    B := C * Sin_b / Sin_g;
  end;
  procedure solve_C_alpha_beta;
  begin
    Find_third_angle(gam,alp,bet);
    solve_AB;
  end;
  procedure solve_C_alpha_gamma;
  begin
    Find_third_angle(bet,alp,gam);
    solve_AB;
  end;
  procedure solve_C_beta_gamma;
  begin
    Find_third_angle(alp,bet,gam);
    solve_AB;
  end;

  Procedure test_180;
  begin
    Bad := False;
    if alp+bet > 180 then
      Bad := True;
    if alp+gam > 180 then
      Bad := True;
    if bet+gam > 180 then
      Bad := True;
  end;
  Procedure test_sides;
  Begin
    S_Count := 0;
    sides[1] := A;
    if A > 0 then inc(S_Count);
    sides[2] := B;
    if B > 0 then inc(S_Count);
    sides[3] := C;
    if C > 0 then inc(S_Count);

    OK_To_Solve := false;
    mx := MaxValue(sides);
    mn := MinValue(sides);
    md := (A+B+C) - (mx+mn);
    if Mn = 0 then
      OK_To_Solve := true
    else
      begin
        if (md+mn) > mx then
          OK_To_Solve := true
        else
          begin
            Message := 'The Sum of the two short sides must be greater than the longest side';
            Bad := True;
            OK_To_Solve := False;
          end;

      end;
    Done := Not OK_To_solve;
  end;

  procedure show_Infinity(N : byte);
  begin
    Case N of
      1 : begin
            Tan_alp.Hide;
            Infinity.Show;
            Infinity.Top:=710;
            Tan_bet.Show;
            Tan_gam.Show;
          end;
      2 : begin
            Tan_bet.Hide;
            Infinity.Show;
            Infinity.Top:=745;
            Tan_alp.Show;
            Tan_gam.Show;
          end;
      3 : begin
            Tan_gam.Hide;
            Infinity.Show;
            Infinity.Top:=780;
            Tan_bet.Show;
            Tan_alp.Show;
          end;

    end;
  end;

  procedure Get_Functions;
  begin
    sincos(Rads(alp),sin_a,cos_a);
    sincos(Rads(bet),sin_b,cos_b);
    sincos(Rads(gam),sin_g,cos_g);
    tan_a := Tan(Rads(alp));
    tan_b := Tan(Rads(bet));
    tan_g := Tan(Rads(gam));
    test_proximity_F(sin_a);
    If Sin_a = 1 then Cos_a := 0;
    test_proximity_F(cos_a);
    test_proximity_F(sin_b);
    If Sin_b = 1 then Cos_b := 0;
    test_proximity_F(cos_b);
    test_proximity_F(sin_g);
    If Sin_g = 1 then Cos_g := 0;
    test_proximity_F(cos_g);
    sincos(Rads(alp/2),sin_a1,cos_a1);
    sincos(Rads(bet/2),sin_b1,cos_b1);
    sincos(Rads(gam/2),sin_g1,cos_g1);
    tan_a1 := Tan(Rads(alp/2));
    tan_b1 := Tan(Rads(bet/2));
    tan_g1 := Tan(Rads(gam/2));
    test_proximity_F(sin_a1);
    If Sin_a1 = 1 then Cos_a1 := 0;
    test_proximity_F(cos_a1);
    test_proximity_F(sin_b1);
    If Sin_b1 = 1 then Cos_b1 := 0;
    test_proximity_F(cos_b1);
    test_proximity_F(sin_g1);
    If Sin_g1 = 1 then Cos_g1 := 0;
    test_proximity_F(cos_g1);

    sin_alp.Caption := Ftxt(sin_a,Deci);
    sin_bet.Caption := Ftxt(sin_b,Deci);
    sin_gam.Caption := Ftxt(sin_g,Deci);

    cos_alp.Caption := Ftxt(cos_a,Deci);
    cos_bet.Caption := Ftxt(cos_b,Deci);
    cos_gam.Caption := Ftxt(cos_g,Deci);

    If alp = 90 then show_Infinity(1)
      else tan_alp.Caption := Ftxt(tan_a,Deci);
    If bet = 90 then show_Infinity(2)
      else tan_bet.Caption := Ftxt(tan_b,Deci);
    If gam = 90 then show_Infinity(3)
      else tan_gam.Caption := Ftxt(tan_g,Deci);

    Store_Func_Data;
  end;

  procedure Test_Impossible;
  begin
    Bad := false;
    if (A=B) and ((Alp >= 90) or (Bet >= 90)) then
      begin
        message := 'With A && B equal,  Alpha or Beta cannot be 90° or greater';
        Bad := true;
      end
    else
      if (A=C) and ((Alp >= 90) or (Gam >= 90)) then
        begin
          message := 'With A && C equal,  Alpha or Gamma cannot be 90° or greater';
          Bad:= true;
        end
      else
        if (B=C) and ((Bet >= 90) or (Gam >= 90)) then
          begin
            message := 'With B && C equal,  Beta or Gamma cannot be 90° or greater';
            Bad := true;
          end;
  end;

begin             // SOLVE
  Bad  := False;
  Done := False;
  No_Sol.Hide;
  Txt_Size_1 := trunc(Text_Mutiplier.Position);
  Txt_Size_2 := trunc(Txt_Size_1 * 1.3);
  Show_Txt_Size;
  Display.Refresh;
  Clear_Functions;

  Message := Instruction;

  inp_data[1,1] := Val_A.text    +'.'+Val_A1.text;
  inp_data[2,1] := Val_B.text    +'.'+Val_B1.text;
  inp_data[3,1] := Val_C.text    +'.'+Val_C1.text;
  inp_data[1,2] := Val_alpha.text+'.'+Val_alpha1.text;
  inp_data[2,2] := Val_beta.text +'.'+Val_beta1.text;
  inp_data[3,2] := Val_gamma.text+'.'+Val_gamma1.text;

  Val(inp_data[1,1],A,x);
  Num_data[1,1]:=A;

  Val(inp_data[2,1],B,x);
  Num_data[2,1]:=B;

  Val(inp_data[3,1],C,x);
  Num_data[3,1]:=C;

  Val(inp_data[1,2],alp,x);
  Num_data[1,2]:=alp;

  Val(inp_data[2,2],bet,x);
  Num_data[2,2]:=bet;

  Val(inp_data[3,2],gam,x);
  Num_data[3,2]:=gam;

  if Alp+Bet+Gam > 0 then
    test_180;
  If Bad then
    begin
      Message := 'Sum of any two angles cannot exceed 180°';
      Done := true;
      TT   := 0;
    end;
  If A+B+C = 0 then
    begin
      OK_To_Solve := false;
      Message := 'You must provide at least one side';
      done :=true;
      TT := 0;
    end
  else
    begin
      test_sides;
    end;

  if OK_to_Solve then
    begin
      calc_known;
      if known < 7 then
        begin
          Message := 'Please enter THREE dimensions';
          Bad := True;
        end
      else
        begin
          test_impossible;
          if NOT Bad then
            case known of
               7 : begin
                     Check_Type;
                     solve_ABC;
                   end;
              11 : begin solve_AB_alpha; end;
              13 : begin solve_AC_alpha; end;
              14 : begin solve_BC_alpha; end;
              19 : begin solve_AB_beta; end;
              21 : begin solve_AC_beta; end;
              22 : begin solve_BC_beta; end;
              25 : begin solve_A_alpha_beta; end;
              26 : begin solve_B_alpha_beta; end;
              28 : begin solve_C_alpha_beta; end;
              35 : begin solve_AB_gamma; end;
              37 : begin solve_AC_gamma; end;
              38 : begin solve_BC_gamma; end;
              41 : begin solve_A_alpha_gamma; end;
              42 : begin solve_B_alpha_gamma; end;
              44 : begin solve_C_alpha_gamma; end;
              49 : begin solve_A_beta_gamma; end;
              50 : begin solve_B_beta_gamma; end;
              52 : begin solve_C_beta_gamma; end;
            end;
        end;

  if not done then
    begin
      Val(TriangleSolution.DecP.Text,Deci,x);

      Sides[1] := A;
      Sides[2] := B;
      Sides[3] := C;

      Tri_Data.A:=A;
      Tri_Data.B:=B;
      Tri_Data.C:=C;
      Tri_Data.Alp:=Alp;
      Tri_Data.Bet:=Bet;
      Tri_Data.Gam:=Gam;
      Tri_Data.Alp1:=Alp/2;
      Tri_Data.Bet1:=Bet/2;
      Tri_Data.Gam1:=Gam/2;

      Mx := MaxValue(Sides);
      Mn := MinValue(Sides);
      Md := (A+B+C)-Mx-Mn;

      Find_type;
      Get_Functions;
      CalcWidth_Height;
      If Bad
        then
          begin
            Message := 'Cannot Solve - check Input Data';
          end
        else
          begin
            Area := TriHeight * TriWidth / 2;    // (A * B * sin_g) / 2 ;
            Peri := A+B+C;
            Draw_Image;
            write_sides;
            write_angles;
            write_APH;
          end;
    end;
  end;
  If Bad then
    begin
      Done := True;
      No_Sol.Show;
      Windows.Beep(1000, 1000);
    end;

  MessageBoard.caption := Message;
end;

procedure TTriangleSolution.Text_MutiplierMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Txt_Size_1 := trunc(Text_Mutiplier.Position);
  Txt_Size_2 := trunc(Txt_Size_1 * 1.3);
  Show_Txt_Size;
  Save_Settings;
end;

procedure TTriangleSolution.Use2ScrClick(Sender: TObject);
begin
  if Use2Scr.Width = 50 then
    begin
      UsingDisplay2 := true;
      Use2Scr.Width := 100;
      Use2Scr.Left  := 1075;
      TriangleSolution.Width:=2425;
      with Display do
        begin
          Left   := 1350;
          Top    := 0;
          Width  := 1000;
          Height := 1000;
          ScaleFactor := 2;
        end;
    end
  else
    begin
      UsingDisplay2   := False;
      Use2Scr.Width := 50;
      Use2Scr.Left  := 1100;
      TriangleSolution.Width:=1230;
      with Display do
        begin
          Left   := 50;
          Top    := 48;
          Width  := 600;
          Height := 600;
          ScaleFactor := 1;
        end;
    end;
end;

Procedure initialise;
var x, y : byte;
begin
  If ScaleFactor <> 2 Then
    ScaleFactor := 1;
  Done        := false;
  OK_to_Solve := false;
  Message     := ' ';
  known       := 0;
  A  := 0; B  := 0; C  := 0;
  alp:= 0; bet:= 0; gam:= 0;  Delta := 0; Theta:= 0;
  for x := 1 to 3 do
    for y := 1 to 2 do
      begin
        Inp_data[x,y] := ' ';
        Num_data[x,y] := 0;
      end;

  sin_a := 0;
  cos_a := 0;
  tan_a := 0;
  sin_b := 0;
  cos_b := 0;
  tan_b := 0;
  sin_g := 0;
  cos_g := 0;
  tan_g := 0;

  sin_a1 := 0;
  cos_a1 := 0;
  tan_a1 := 0;
  sin_b1 := 0;
  cos_b1 := 0;
  tan_b1 := 0;
  sin_g1 := 0;
  cos_g1 := 0;
  tan_g1 := 0;

  Area  := 0;
  Peri  := 0;

  TriHeight := 0;
  Height_2  := 0;
  Height_3  := 0;
  TriWidth  := 0;
  Circ_Dia  := 0;
  Circ_Rad  := 0;
  Insc_Dia  := 0;
  Insc_Rad  := 0;
  TT        := 0;
  TriangleSolution.TOS_Num.Caption := '000';

  Val(TriangleSolution.DecP.Text,Deci,x);

  with TriangleSolution do
    begin
      Tri_Type.text := Tri_name[TT];
      MessageBoard.caption := Instruction;
      Swapped_Arrow.Hide;
    end;
  Read_Settings;
end;

procedure TTriangleSolution.FormCreate(Sender: TObject);
begin
  TriangleSolution.Width := 1250;
  Left  := 30;
  Top   := 50;
  ConfigDir := GetAppConfigDir(Good);
  Read_Path;
  System.Assign(Settings, DataPath +'Settings.DTA');
  if Screen.DesktopWidth > Screen.Width then
    TwinScreen := true
  else
    TwinScreen := false;
  if TwinScreen then
    Use2Scr.Show;

  initialise;
end;

procedure TTriangleSolution.Clear_Common;
  procedure Clear_Functions;
  begin
    Sin_Alp.Text:=blank;
    Sin_Bet.Text:=blank;
    Sin_Gam.Text:=blank;
    Cos_Alp.Text:=blank;
    Cos_Bet.Text:=blank;
    Cos_Gam.Text:=blank;
    Tan_Alp.Text:=blank;
    Tan_Bet.Text:=blank;
    Tan_Gam.Text:=blank;
  end;
  procedure Clear_Circles;
  begin
    Val_CircDia.Text:=blank;
    Val_CircRad.Text:=blank;
    Val_Circ_X.Text :=blank;
    Val_Circ_Y.Text :=blank;
    Val_InscDia.Text:=blank;
    Val_InscRad.Text:=blank;
    Val_Insc_X.Text :=blank;
    Val_Insc_Y.Text :=blank;
  end;
begin
  Tri_type.text  := tri_name[0];
  Val_Area.text  := blank;
  Val_Peri.text  := blank;
  Val_Height.Text:= blank;
  Val_Width.Text := blank;
  Orientation.Caption:=blank;
  Clear_Functions;
  Clear_Circles;
  Display.Refresh;
  TOS_Num.Caption:='000';
  Pythag.Hide;
  No_Sol.Hide;
  Infinity.Hide;
  Swapped_Arrow.Hide;
  MessageBoard.caption := Instruction;
end;
procedure TTriangleSolution.ClearClick(Sender: TObject);
begin
  Val_A.text      := blank;
  Val_A1.text     := blank;
  Val_B.text      := blank;
  Val_B1.text     := blank;
  Val_C.text      := blank;
  Val_C1.text     := blank;
  Val_alpha.text  := blank;
  Val_alpha1.text := blank;
  Val_beta.text   := blank;
  Val_beta1.text  := blank;
  Val_gamma.text  := blank;
  Val_gamma1.text := blank;
  Rad_alpha.text  := blank;
  Rad_alpha1.text := blank;
  Rad_beta.text   := blank;
  Rad_beta1.text  := blank;
  Rad_gamma.text  := blank;
  Rad_gamma1.text := blank;
  Alp_MinSec.Caption:=blank;
  Bet_MinSec.Caption:=blank;
  Gam_MinSec.Caption:=blank;
  Clear_Common;
end;
procedure TTriangleSolution.Clear_AlBeClick(Sender: TObject);
begin
  Val_alpha.text  := blank;
  Val_alpha1.text := blank;
  Val_beta.text   := blank;
  Val_beta1.text  := blank;
  Rad_alpha.text  := blank;
  Rad_alpha1.text := blank;
  Rad_beta.text   := blank;
  Rad_beta1.text  := blank;
  Alp_MinSec.Caption:=blank;
  Bet_MinSec.Caption:=blank;
  Clear_Common;
end;
procedure TTriangleSolution.Clear_BeGaClick(Sender: TObject);
begin
  Val_beta.text   := blank;
  Val_beta1.text  := blank;
  Val_gamma.text  := blank;
  Val_gamma1.text := blank;
  Rad_beta.text   := blank;
  Rad_beta1.text  := blank;
  Rad_gamma.text  := blank;
  Rad_gamma1.text := blank;
  Bet_MinSec.Caption:=blank;
  Gam_MinSec.Caption:=blank;
  Clear_Common;
end;
procedure TTriangleSolution.Clear_AClick(Sender: TObject);
begin
  Val_A.text      := blank;
  Val_A1.text     := blank;
  Clear_Common;
end;
procedure TTriangleSolution.Clear_ABClick(Sender: TObject);
begin
  Val_A.text      := blank;
  Val_A1.text     := blank;
  Val_B.text      := blank;
  Val_B1.text     := blank;
  Clear_Common;
end;
procedure TTriangleSolution.Clear_BCClick(Sender: TObject);
begin
  Val_B.text      := blank;
  Val_B1.text     := blank;
  Val_C.text      := blank;
  Val_C1.text     := blank;
  Clear_Common;
end;
procedure TTriangleSolution.Clear_BClick(Sender: TObject);
begin
  Val_B.text      := blank;
  Val_B1.text     := blank;
  Clear_Common;
end;
procedure TTriangleSolution.Clear_CClick(Sender: TObject);
begin
  Val_C.text      := blank;
  Val_C1.text     := blank;
  Clear_Common;
end;
procedure TTriangleSolution.Clear_AlphaClick(Sender: TObject);
begin
  Val_alpha.text  := blank;
  Val_alpha1.text := blank;
  Rad_alpha.text  := blank;
  Rad_alpha1.text := blank;
  Alp_MinSec.Caption:=blank;
  Clear_Common;
end;
procedure TTriangleSolution.Clear_BetaClick(Sender: TObject);
begin
  Val_beta.text   := blank;
  Val_beta1.text  := blank;
  Rad_beta.text   := blank;
  Rad_beta1.text  := blank;
  Bet_MinSec.Caption:=blank;
  Clear_Common;
end;
procedure TTriangleSolution.Clear_GamaClick(Sender: TObject);
begin
  Val_gamma.text  := blank;
  Val_gamma1.text := blank;
  Rad_gamma.text  := blank;
  Rad_gamma1.text := blank;
  Gam_MinSec.Caption:=blank;
  Clear_Common;
end;
procedure TTriangleSolution.Clear_SidesClick(Sender: TObject);
begin
  Val_A.text      := blank;
  Val_A1.text     := blank;
  Val_B.text      := blank;
  Val_B1.text     := blank;
  Val_C.text      := blank;
  Val_C1.text     := blank;
  Clear_Common;
end;

procedure TTriangleSolution.DecPChange(Sender: TObject);
begin
  Save_Settings;
end;

procedure TTriangleSolution.Clear_anglesClick(Sender: TObject);
begin
  Val_alpha.text  := blank;
  Val_alpha1.text := blank;
  Val_beta.text   := blank;
  Val_beta1.text  := blank;
  Val_gamma.text  := blank;
  Val_gamma1.text := blank;
  Rad_alpha.text  := blank;
  Rad_alpha1.text := blank;
  Rad_beta.text   := blank;
  Rad_beta1.text  := blank;
  Rad_gamma.text  := blank;
  Rad_gamma1.text := blank;
  Alp_MinSec.Caption:=blank;
  Bet_MinSec.Caption:=blank;
  Gam_MinSec.Caption:=blank;
  Clear_Common;
end;

procedure TTriangleSolution.Halve_alphaClick(Sender: TObject);
begin
  alp := alp / 2;
  String_Angle(1);
end;
procedure TTriangleSolution.Halve_BetaClick(Sender: TObject);
begin
  bet := bet / 2;
  String_Angle(2);
end;
procedure TTriangleSolution.Halve_GamaClick(Sender: TObject);
begin
  gam := gam / 2;
  String_Angle(3);
end;

procedure TTriangleSolution.PreSet_A30Click(Sender: TObject);
begin
  Alp := 30;
  String_Angle(1);
end;
procedure TTriangleSolution.PreSet_A45Click(Sender: TObject);
begin
  Alp := 45;
  String_Angle(1);
end;
procedure TTriangleSolution.PreSet_A60Click(Sender: TObject);
begin
  Alp := 60;
  String_Angle(1);
end;
procedure TTriangleSolution.PreSet_A90Click(Sender: TObject);
begin
  Alp := 90;
  String_Angle(1);
end;
procedure TTriangleSolution.PreSet_A120Click(Sender: TObject);
begin
  Alp := 120;
  String_Angle(1);
end;
procedure TTriangleSolution.PreSet_A135Click(Sender: TObject);
begin
  Alp := 135;
  String_Angle(1);
end;

procedure TTriangleSolution.PreSet_B30Click(Sender: TObject);
begin
  Bet := 30;
  String_Angle(2);
end;
procedure TTriangleSolution.PreSet_B45Click(Sender: TObject);
begin
  Bet := 45;
  String_Angle(2);
end;
procedure TTriangleSolution.PreSet_B60Click(Sender: TObject);
begin
  Bet := 60;
  String_Angle(2);
end;
procedure TTriangleSolution.PreSet_B90Click(Sender: TObject);
begin
  Bet := 90;
  String_Angle(2);
end;
procedure TTriangleSolution.PreSet_B120Click(Sender: TObject);
begin
  Bet := 120;
  String_Angle(2);
end;
procedure TTriangleSolution.PreSet_B135Click(Sender: TObject);
begin
  Bet := 135;
  String_Angle(2);
end;

procedure TTriangleSolution.PreSet_G30Click(Sender: TObject);
begin
  Gam := 30;
  String_Angle(3);
end;
procedure TTriangleSolution.PreSet_G45Click(Sender: TObject);
begin
  Gam := 45;
  String_Angle(3);
end;
procedure TTriangleSolution.PreSet_G60Click(Sender: TObject);
begin
  Gam := 60;
  String_Angle(3);
end;
procedure TTriangleSolution.PreSet_G90Click(Sender: TObject);
begin
  Gam := 90;
  String_Angle(3);
end;

procedure Print_Data;
begin
  Printer.Title := 'Tri-'+IntToStr(Tri_Data.TOS)+Tri_Name[TT]+'.PDF';
  with Printer do
   try
     BeginDoc;
     Canvas.Font.Color := DefCol;

     with Tri_Data do
       begin

       end;

   finally
     EndDoc;
   end;

end;
procedure TTriangleSolution.Print_Btn1Click(Sender: TObject);
begin
  if A=0 then
    begin
      MessageBoard.Caption := 'No data yet provided !!';
      Exit;
    end
  else
    Print_Data;
end;

procedure TTriangleSolution.SelectClick(Sender: TObject);
begin
  PrinterSetup.Execute;
end;

procedure TTriangleSolution.PreSet_G120Click(Sender: TObject);
begin
  Gam := 120;
  String_Angle(3);
end;
procedure TTriangleSolution.PreSet_G135Click(Sender: TObject);
begin
  Gam := 135;
  String_Angle(3);
end;

end.

