You are on page 1of 7

A MATLAB polygonal integrator

January 2006

Adrian B. Biran, Technion Faculty of Mechanical Engineering,


Companion software for the book Ship Hydrostatics and Stability,
revised reprint, Oxford, UK, Elsevier Butterworth-Heinemann.
c 2006, A.B. Biran.
Copyright

Introduction and instructions for use

Many engineering problems require the knowledge of the geometrical properties of a plane figure. This task can be performed by numerical integration
using, for example, the trapezoidal or Simpsons rule. Since the invention of
the planimeter by Amsler, around 1854, Naval Architects used mechanical
analog computers, specifically planimeters, integrators and integraphs to calculate the geometrical properties by following a closed contour on the lines
drawing or on intermediate, specially-prepared graphs. In this document we
describe a MATLAB function that accepts as input the array of coordinates
1

of the vertices of a polygonal figure. Let the coordinates of the i-th point be
xi , yi . Then, the function can be called as
[ PROPERTIES ] = pintegrator(X);}
where

x1

X=

x2 . . . x n x1

y1 y2 . . . yn y1

The output consists of a MATLAB array named PROPERTIES within the


programme. This array contains the following geometrical properties of the
polygonal figure
1. polygonal area;
2. x-coordinate of centroid;
3. y-coordinate of centroid
4. second moment about barycentric y-axis
5. second moment about barycentric y-axis
6. product of inertia about barycentric axes
7. radius of gyration about barycentric y-axis
8. radius of gyration about barycentric x-axis
9. maximum principal moment of inertia
2

10. minimum principal moment of inertia


11. maximum radius of gyration about principal axes
12. minimum radius of gyration about principal axes
These, and additional data are also printed on a file called pintegrator.out. The output stored in the array PROPERTIES can be further processed
by any of the available MATLAB tools. A plot of the digitized polygon and
its principal axes is also produced.
To calculate the area of the polygonal figure, the programme calls the
MATLAB built-in function POLYAREA. The calculation of the perimeter is
based on repeated invocations of the MATLAB function NORM. The first and
second moments of the polygonal area are calculated by means of Greens
theorem. A statement of this theorem is
ZZ

I
L

M dx + N dy =

N
M

x
y

dxdy

where L is the boundary of the area S (see, for example, Finney, 1988, pp.
102739, or ONeil, 2003, p. 5659). Functions M and N suitable for the
calculation of the geometrical properties can be found, for example, in a paper
by Ken Turkowksi available on the web. The boundary L must be followed
in the counterclockwise sense, that is so as to have the area A always on the
left of the cursor.
If a figure has an axis of symmetry, that axis is also a principal axis.
Small errors of digitization can yield wrong principal axes. The error can
3

be important if the two moments of inertia about the barycentric axes are
nearly equal.
If the coordinates of polygonal vertices must be measured in a given
drawing, scan that drawing to obtain a graphic file (for example a JPEG
file) and use the function digitizer. For waterlines or other symmetrical
figures use the function wldigitizer, for curves of statical stability use the
function scdigitizer, and for body plans the function bpdigitizer.
The function digitizer calls the function point. Therefore, the file of
the latter function must be included in the same directory as the function
digitizer.

An example

The file Zfigure.m (stored on the same site with this document) contains
the coordinates of the vertices of a Z-shaped figure as exemplified in Beer
and Johnston (1998). See Figure 1. Assuming that the dimensions are given
in m, the properties of the above figure are

Z test
4

3.5

2.5

1.5

0.5

0
2

1.5

0.5

0.5

1.5

2.5

area

4.500

m2

x-coordinate of centroid

0.250

y-coordinate of centroid

2.000

moment of inertia about given y-axis

7.250

m4

moment of inertia about given x-axis

28.375

m4

product of inertia about given axes

-4.313

m4

moment of inertia about barycentric y-axis

6.969

m4

moment of inertia about barycentric x-axis

10.375

m4

product of inertia about barycentric axes

-6.563

m4

angle of principal axes

37.726

degrees

Figure 1: A Z-shaped figure

maximum moment of inertia about principal axes 15.452


5
minimum moment of inertia about principal axes
1.892

m4
m4

Above we call barycentric axes the axes with the origin of coordinates in
the centroid of the figure. Beer and Johnston (1998) call these axes centroidal.
To exercise, the reader can call the function with the commands
Zfigure
[ PROPERTIES ] = pintegrator(Z);

Figure 2: Figure produced by the function pintegrator


The function plots the digitized figure and its principal axes as shown in
Figure 2.

Bibliography

Beer, F.P., and Johnston, E.R. Jr (1998), Vector mechanics for engineers,
3d SI metric edition, Toronto, McGraw-Hill Ryerson.
Finney, R.L. (1988), Calculus and analytic geometry, 7th ed., ReadingMassachusetts, Addison Wesley publishing Company.
ONeil, P.V. (2003), Advanced engineering mathematics, 5th ed., Pacific
Grove - CA, Thomson Brooks/Cole.
Turkowski, K. (1997), Computing 2D polygon moments using Greens
Theorem, http://www.worldserver.com/turk/computergraphics/Moments.pdf.

You might also like