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

Revision as of 06:14, 5 November 2013 by MassBot1 (talk | contribs) (Created page with "<syntaxhighlight lang="ada" line start="1" enclose="div">package body Geometry.Magic is function Moment(OC : Object'Class) return Float is -- This is class wide since t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 1package body Geometry.Magic is
 2
 3  function Moment(OC : Object'Class) return Float is
 4    -- This is class wide since the same formula applies to all
 5    -- types.  Note that it illustrates both the inheritance of a
 6    -- component (X_Coord) and an operation (Area). The call of
 7    -- Area is a dispatching call. It is assumed that the units
 8    -- are such that the Mass equals the Area and that the
 9    -- acceleration due to gravity (g) is 1.
10  begin
11    return OC.X_Coord * Area(OC);
12  end Moment;
13
14  function MO(OC : Object'Class) return Float is
15    -- This is also class wide since again the same formula
16    -- applies to all types. 
17    --    It uses the so-called parallel axis theorem that the
18    -- moment of inertia about another point (here the origin)
19    -- equals the sum of the moment of inertia about the center of
20    -- gravity (MI) plus the Mass times the square of the distance
21    -- of the center of gravity from the origin.  Remember that
22    -- the units are such that the Mass equals the Area.
23    --    The calls of MI, Area and Distance are dispatching calls.
24  begin
25    return MI(OC) + Area(OC) * Distance(OC)**2;
26  end MO;
27
28end Geometry.Magic;