3 This code accompanies the paper:
5 Brian Mirtich, "Fast and Accurate Computation of
6 Polyhedral Mass Properties," journal of graphics
7 tools, volume 1, number 2, 1996.
9 It computes the ten volume integrals needed for
10 determining the center of mass, moments of
11 inertia, and products of inertia for a uniform
12 density polyhedron. From this information, a
13 body frame can be computed.
15 To compile the program, use an ANSI compiler, and
18 % cc volInt.c -O2 -lm -o volInt
23 26 Jan 1996 Program creation.
25 3 Aug 1996 Corrected bug arising when polyhedron density
26 is not 1.0. Changes confined to function main().
27 Thanks to Zoran Popovic for catching this one.
31 2. POLYHEDRON GEOMETRY FILES
33 The program reads a data file specified on the
34 command line. This data file describes the
35 geometry of a polyhedron, and has the following
45 x_{N-1} y_{N-1} z_{N-1}
49 k1 v_{1,1} v_{1,2} ... v_{1,k1}
50 k2 v_{2,1} v_{2,2} ... v_{2,k2}
54 kM v_{M,1} v_{M,2} ... v_{M,kM}
58 N number of vertices on polyhedron
59 x_i y_i z_i x, y, and z coordinates of ith vertex
60 M number of faces on polyhedron
61 ki number of vertices on ith face
62 v_{i,j} jth vertex on ith face
66 First the number of vertices are specified. Next
67 the vertices are defined by listing the 3
68 coordinates of each one. Next the number of faces
69 are specified. Finally, the faces themselves are
70 specified. A face is specified by first giving
71 the number of vertices around the polygonal face,
72 followed by the (integer) indices of these
73 vertices. When specifying indices, note that
74 they must be given in counter-clockwise order
75 (when looking at the face from outside the
76 polyhedron), and the vertices are indexed from 0
77 to N-1 for a polyhedron with N faces.
79 White space can be inserted (or not) as desired.
80 Three example polyhedron geometry files are included:
82 cube A cube, 20 units on a side, centered at
83 the origin and aligned with the coordinate axes.
85 tetra A tetrahedron formed by taking the convex
86 hull of the origin, and the points (5,0,0),
89 icosa An icosahedron with vertices lying on the unit
90 sphere, centered at the origin.
94 3. RUNNING THE PROGRAM
98 % volInt <polyhedron geometry filename>
100 The program will read in the geometry of the
101 polyhedron, and the print out the ten volume
104 The program also computes some of the mass
105 properties which may be inferred from the volume
106 integrals. A density of 1.0 is assumed, although
107 this may be changed in function main(). The
108 center of mass is computed as well as the inertia
109 tensor relative to a frame with origin at the
110 center of mass. Note, however, that this matrix
111 may not be diagonal. If not, a diagonalization
112 routine must be performed, to determine the
113 orientation of the true body frame relative to
114 the original model frame. The Jacobi method
115 works quite well (see Numerical Recipes in C by
122 1. The volume integration code has been written
123 to match the development and algorithms presented
124 in the paper, and not with maximum optimization
125 in mind. While inherently very efficient, a few
126 more cycles can be squeezed out of the algorithm.
127 This is left as an exercise. :)
129 2. Don't like global variables? The three
130 procedures which evaluate the volume integrals
131 can be combined into a single procedure with two
132 nested loops. In addition to providing some
133 speedup, all of the global variables can then be
136 3. The polyhedron data structure used by the
137 program is admittedly lame; much better schemes
138 are possible. The idea here is just to give the
139 basic integral evaluation code, which will have
140 to be adjusted for other polyhedron data
143 4. There is no error checking for the input
144 files. Be careful. Note the hard limits
145 #defined for the number of vertices, number of
146 faces, and number of vertices per faces.