Yurttas/PL/IL/Ada-95/OO/GEO/geometry-triangles.adb

From ZCubes Wiki
Revision as of 06:14, 5 November 2013 by MassBot1 (talk | contribs) (Created page with "<syntaxhighlight lang="ada" line start="1" enclose="div">with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions; package body Geometry.Triangles is ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
 1with Ada.Numerics.Elementary_Functions;
 2use Ada.Numerics.Elementary_Functions;
 3
 4package body Geometry.Triangles is
 5
 6  function Area(T : Triangle) return Float is
 7    -- The area is computed using Heron's formula.
 8    -- S is half the perimeter.
 9
10    S : constant Float := 0.5 * (T.A + T.B + T.C);
11  begin
12    return Sqrt(S * (S - T.A) * (S - T.B) * (S - T.C));
13  end Area;
14
15  function MI(T : Triangle) return Float is
16    -- This formula is not well known.
17  begin
18    return Area(T) * (T.A**2 + T.B**2 + T.C**2) / 36.0;
19  end MI;
20
21  function Name(T : Triangle) return String_8 is
22  begin
23    return "Triangle";
24  end Name;
25
26end Geometry.Triangles;