1 Introduction

When it comes to estimating masses or computing gravitational centers for objects of varying density almost everywhere discretized approximations are used. Often their accuracy is not even questioned. Surprisingly, it is neither a very complex problem nor bound to numerical trade-offs between computation cost and accuracy. As used in finite element methods (FEM) [23, 24], our techniques are based on tetrahedra as the underlying geometry primitive. Density fields are accurately represented by specifying the density at the four vertices. The analytically derived closed-form integrals for mass properties are expressed with simple matrix-vector multiplications. In Sect. 2, we derive the concept, demonstrate its versatile applicability in Sect. 3 and conclude in Sect. 4 with numerical comparisons and a quantitative evaluation.

1.1 Contributions

In our paper, we briefly review the mathematical basis that allows for accurate solutions of mass and mass-center integrals of objects with varying density. It is simple as computations for tetrahedra with constant density are easily extended towards varying density. It is precise due to the use of a tet-mesh itself as input and therefore avoiding aliasing bias from discretization, as it is common in state-of-the-art applications using axis-aligned voxelizations. It is fast as computations can be implemented as matrix-vector multiplications, suitable for vectorized or GPU execution. It is versatile because the framework is not limited to density and can be extended to integrate arbitrary linear properties over a volume.

Our application framework, introduced in Sect. 3, can be summarized with the following main contributions:

  • Arbitrary Objects The solutions, known for tetrahedra, can be straightforward generalized to arbitrary polyhedra. We can accurately determine mass properties for any tetrahedralized input object in specified density fields.

  • Optimizing Density We can also invert the problem and optimize a parameterized density field for an object and given mass properties.

  • Approaching nonlinearity Arbitrary nonlinear functions can be approximated in a Taylor-like piecewise linear fashion, limited in accuracy only by the tetrahedralization’s resolution.

  • Additive manufacturing Combining the former two contributions, we eventually propose to 3D-print objects of nonlinear density with optimized mass properties for balance or rotation-aligned inertia momentum.

  • Expressing energy functions As the method is not bound to only physical characteristics, we extend a Lloyd relaxation procedure based on \(L_{2}\) Voronoi cells, using the concept to replace the cells energy integral with an accurate closed form solution for an \(L_{\infty }\) objective function.

1.2 Related work

Over the last few years, 3D printing not only attracted the do-it-yourself hobbyist community but also gained popularity in various industrial applications. Nowadays, additive manufacturing processes go way beyond stacked layers of plastic and support a wide range of multiple or mixed materials, even including metals. Its widespread use, e.g., in the medical [31] or automotive [11] industry, keep this a relevant research topic.

Hence the general interest of the computer graphics community for analyzing and processing 3D geometry, research in this field also spawned state-of-the-art algorithms aiming at 3D manufacturing. The procedure introduced by Prévost et al. [22] allows 3D models to be balanced in a specific position by shifting the object’s center of gravity over a safe area on which the object eventually stands. Optimized weight distribution is achieved by carving out the object’s interior and deformations of the hull, if necessary. Advancements of this technique optimize objects to have rotation-symmetric weight distributions and allow them to spin-like toy-tops [1]. Multistable balancing states are accomplished by using movable masses [21]. However, established techniques for mass property optimization are still based on approximations of the actual volume and mass distribution using quantized voxelizations. The approach by Musialski et al. [18] utilizes offset surfaces for shape and mass property optimization but also relies on binary material distribution. Even publications specialized on varying density for manufacturing [10, 29] discretize their density field with marching cubes [15] or octrees [16] combined with dithering techniques.

Known methods for computing exact mass properties of polyhedral bodies [17] are restricted to constant density. Like ours, they are based on integrals over the volume and surface of an object. A later revision [6] made the concept feasible for implementation. The varying density of polyhedral bodies, however, was first studied in the field of geophysics and concluded with the focus on gravitational fields [5, 7] but not general mass properties. Our approach to computing accurate masses and mass centers under varying density relies on a tetrahedral decomposition of the input object. TetGen [26] is a tetrahedralization tool for polyhedral manifolds based on a Voronoi/Delaunay tessellation. Most recently, TetWild [9] introduced another fast and robust way to tetrahedralize any given 3D triangle soup, providing many adjustable parameters to the user. Our results for examples and applications are based on the outputs of both tools but often specifically on TetGen since it is able to preserve the original input surface. However, any other tet-meshing pipeline will generate equally suitable input as well.

As mentioned with TetGen, tetrahedralization is closely related to Voronoi and Delaunay graphs. In our Sect. 3.5, we introduce a novel approach on Lloyd relaxations (based on Voronoi tessellations) using the \(L_\infty \) norm. Ray et al. proposed to compute meshless Voronoi [25] and restricted power diagrams [2] on the GPU, however, both only in the common \(L_2\) space. It definitely is a promising task to explore combinations of their diagrams and our take on \(L_\infty \) relaxations.

2 Concept

Our goal is to approach mass properties for polyhedral manifolds of varying densities with analytical tools. In order to compute the mass, the center of mass, or other related quantities in a field of varying density that is bounded by a triangle mesh we use closed-form solutions for a tetrahedralization, induced by the given mesh surface. These kinds of approaches are admittedly standard in FEM but so far rarely have been used in computer graphics. Therefore, this section briefly summarizes all important formulas and introduces the geometric concept that allows for computing these quantities exactly for linearly varying density fields inside a tetrahedron. Detailed derivations of the resulting equations are featured in “Appendix A”.

2.1 Problem statement

Fig. 1
figure 1

2D example: Voxelizations are common approximations to determine mass properties under varying density. Tetrahedra allow for accurate representations using precise analytic results

Mesh data structures are the straightforward and, therefore, most common way to store and represent 3D manifolds. Under constant density, mass properties like the center of mass or an inertia momentum can be easily computed directly on a mesh using the divergence theorem. With varying density, however, a volume bounded by arbitrarily shaped polyhedra cannot be directly integrated. A common fallback solution is to approximate the object shape by decomposition into feasible volume entities, usually voxels. However, as illustrated with the 2D example in Fig. 1, the success and precision of the approximation will always be limited by the chosen resolution (for space and values), even hierarchical concepts can only reduce sampling artifacts but not fully avoid them. In contrast, our solution for the computation under varying density is based on the simple idea of an alternative volume representation, namely the tetrahedron. As illustrated on the right in Fig. 1 with a trivially triangulated 2D shape, every 3D shape with a polygonal surface can be decomposed using tetrahedra. With tetrahedra, the mesh’s true shape can be used in all computations and, therefore, corresponding results are free of discretization and aliasing bias.

2.2 Geometry integration

Computing mass properties for the general tetrahedron T, specified in Fig. 2, is trivial for constant density: For example with \(d_i=1\), the mass is equal to the tet-volume and the center of mass is equal to its centroid. However, as the density attributes at each vertex can be individually specified, expressing a linear density field inside the tetrahedron, the computation of mass and mass center changes. Instead, as in FEM [23, 24], we utilize a simple basis case in a linear density field, for which the integration is solved analytically. A linear combination of four base cases (one per vertex) already gives the desired properties for a general tetrahedron.

Fig. 2
figure 2

A general tetrahedron T with varying density, defined by its four vertices \(v_i\). In addition to their geometrical dimensions (xyz), each vertex is attributed with a fourth density dimension d

Fig. 3
figure 3

The basis case for an integrable tetrahedron with \(d_D=1\) and \(d_{A,B,C} = 0\). The density gradient over the extent of h is visualized with fading blue. \(\overrightarrow{w}\) indicates the center of mass vector

2.3 Mass properties for arbitrary tetrahedra

Mass Due to linearity, the mass for a tetrahedron with four different density values at its vertices can be simply expressed as the mean of these values times the volume, formulated in Eq. 1.

$$\begin{aligned} \begin{aligned} {\mathbf {M}}_T&= {\mathbf {V}}_T \frac{d_A + d_B + d_C + d_D}{4}\\ \end{aligned} \end{aligned}$$
(1)

Center of Mass As expressed in Eq. 2, the mass center computes as a weighted sum of vertex positions and their normalized density values. An extended derivation for the combination of the four base cases to this general form is included in Eq. 12.

$$\begin{aligned} {\mathbf {C}}_T&= \frac{1}{5} \bigg (A + B + C + D \bigg .+ \bigg .\frac{A\cdot d_A {+} B\cdot d_B + C\cdot d_C + D\cdot d_D}{d_A + d_B + d_C + d_D}\bigg ) \end{aligned}$$
(2)

3 Application

With the presented approach, one can now calculate the mass and further mass properties of tet-meshes with arbitrary density fields efficiently and exactly. The power of the approach will be demonstrated in three different application scenarios: For example, as a fast and accurate replacement for widespread voxel-based approximations of arbitrary objects’ mass properties. Further, it can be used to optimize the density distribution inside an object to obtain a given center of mass or a stable rotation axis, potentially even with nonlinear density fields. By introducing a closed-form solution, our concept even allows us to formulate an objective function in a volumetric Lloyd relaxation process, which was so far not analytically feasible.

3.1 Mass properties of arbitrary objects

With the techniques, introduced in Sect. 2, to compute mass and center of mass for general tetrahedra, we can generalize this concept further and approach arbitrary polyhedral manifolds: Objects are partitioned into tetrahedra, mass properties are determined individually, and results eventually recombined. Any tetrahedral mesh is suitable as input for our method; if the model is not already available as tetrahedral mesh, it can easily be generated using freely available tools like TetGen [26] or TetWild [9]. “Appendix C” proves the concept to be invariant of the actual tetrahedralization.

$$\begin{aligned} \begin{aligned} {\mathbf {M}}_{\mathbf {O}}&= \sum _{T_i\in {\mathbf {O}}} {\mathbf {M}}_{T_i}\\ {\mathbf {C}}_{\mathbf {O}}&= \frac{1}{{\mathbf {M}}_{\mathbf {O}}}\sum _{T_i\in {\mathbf {O}}} {\mathbf {M}}_{T_i} {\mathbf {C}}_{T_i} \end{aligned} \end{aligned}$$
(3)

For an object \({\mathbf {O}}\) and a given density-field, one can now compute the accurate mass \({\mathbf {M}}_{T_i}\) and center of mass \({\mathbf {C}}_{T_i}\) for all tetrahedra \(T_i \in {\mathbf {O}}\) using Eqs. 1 and 2, respectively. These calculations can be executed very efficiently, using fast matrix-vector multiplications. As formulated in Eq. 3, the object’s overall mass is obtained by simple summation and the center of mass as mass-weighted dot-product. Further, one may extend the derivation, as described by Tonon [28], for the inertia tensor \(\Theta _\mathbf {T_i}\) of a general tetrahedron with specified density values of the individual vertices. Following the rules for rigid bodies and the parallel axis theorem, one can derive further mass properties, e.g., the moment of inertia as formulated with the inertia tensor \(\Theta _{\mathbf {O}}\) in Eq. 4, where \({\mathbf {I}}_3\) is the \(3{\times }3\) identity matrix and \(\otimes \) the outer product.

$$\begin{aligned} \begin{aligned} \hat{{\mathbf {C}}}_{T_i}&= {\mathbf {C}}_{T_i} - {\mathbf {C}}_{\mathbf {O}}\\\Theta _{\mathbf {O}}&= \sum _{T_i\in {\mathbf {O}}} \Theta _\mathbf {T_i} + {\mathbf {M}}_{T_i} \left( |\hat{{\mathbf {C}}}_{T_i}|^2 {\mathbf {I}}_3 - \hat{{\mathbf {C}}}_{T_i} \otimes \hat{{\mathbf {C}}}_{T_i} \right) \\ \end{aligned} \end{aligned}$$
(4)

3.2 Optimizing density fields

Now, that an object’s center of mass can be determined for a given density field, one can invert the problem and fit a density field to an object where the mass properties are given. As an exemplary use case, we approached the make-it-stand challenge described by Prévost et al. [22] to balance objects in a given pose. The center of mass has to be within certain boundaries of a projected surface polygon on which the object is supposed to be balanced. However, a solution to this problem is limited by the following constraints: (i) Negative mass is reasonable only in theoretical fields of physics, so we limit our model to the realm of positive density for now. (ii) Zero density is a special case that can be modeled with our concept, e.g., with \(d_i=0\). (iii) The shape of an object together with constraints (i) and (ii) will put some limits on the achievable location of an object’s center of mass, e.g., it simply cannot pass a certain point.

Fig. 4
figure 4

Left: The parameterization of a simplified density field d(x) with parameters rs and t. Right: Embedding of the object, with angles \(\alpha \), \(\beta \) and offset \(o_x\)

Fig. 5
figure 5

An unstable input of three spheres and a figure which is supposed to stand upside down. Prévost et al. [22] managed to balance the objects by deforming them, caving out the interior and shifting the center of mass over a defined safe-region. Our balanced version of the spheres can also be balanced on a small flattened face, the standing version will roll into this position on its own, due to its low center of gravity. Varying density is sufficient to balance the objects, deformation is not required. As reference for Table 2, the spheres are scaled to have a diameter of 1 and MrHumpty has a hand-to-hand width of 2

Rather than optimizing the per-vertex density directly, let’s first consider a simplified density field as illustrated in Fig. 4. We utilize two planes that separate volumes of constant minimum \(d_{\min }\) and maximum density \(d_{\max }\) respectively, sandwiching a slice of volume of width r with linearly growing density \(\in [d_{\min },d_{\max }]\). To simplify many computation steps we fix the density field to be axis aligned, i.e., the planes are parallel to the yz-plane. As accommodation for this fixed orientation of the field, the optimization needs to rotate and to translate the object accordingly instead. To realize the arbitrary location of the bisection-planes in the density function, we have to prepare our input mesh by intersecting some of the tetrahedra, see “Appendix B” for details. The energy to be minimized is formulated as the Euclidean distance \(E=|{\mathcal {C}}-{\mathbf {C}}_O|\) between a target point \({\mathcal {C}}\) and the object’s current center of mass \({\mathbf {C}}_O\) when embedded in the density field, obviously with respect to the object’s rotated and translated state.

The optimization energy is smooth and in some sense probably differentiable but deriving gradients is left for future work. In our experiments, we used Powell’s method [20] to minimize the objective function.

Results Figure 5 compares our balanced objects to cross-sections of Prévost et al. Their proposed method found a solution to make the three spheres stand, by carving out the voxelized interior and deforming the object. To move the mass center of the Spheres into the balance region, the top sphere is shrunk and the bottom sphere is enlarged. For the MrHumpty figure to stand upside down, the belly is enlarged and half the interior carved out to compensate for the off-axis legs. In our results, the objects remain untouched as they are only embedded in an optimized density field. As our output geometry incorporates the input, error measures like the Hausdorff distance are simply 0.

Our first experiment meets the same conditions as Prévost et al. where the center of gravity only has to be on the central vertical axis of the bottom sphere so that the object is in balance. For our next experiment we chose the center of mass to also be located centered in the bottom sphere, but 10% of the sphere’s radius below its horizontal equator-line. Due to this low center of gravity, the standing spheres would roll into this position on their own (Table 1).

Table 1 Parameters of the density field, shown in Fig. 4, to be determined by the optimization
Table 2 The parameters for the density function, specified in Fig. 4 and Table 1, optimized for balancing the objects, shown in Fig. 5 with \(\beta = 0\) and \(t = 1\)

Our optimization managed to define density fields for which the object’s center of mass is exactly on the specified axis or target point respectively. The results have regions of constant minimum and maximum density with a tilted and shifted gradient between them. Due to the symmetry of the objects, the angle \(\beta \) is zero. To approach somewhat reasonable manufacturing limits, we set \(t = 1~(\mathrel {\hat{=}} d_{\min })\). The other found parameters are given in Table 2. Results of this comparison should be seen as a theoretical proof of concept, as this rather unconstrained optimization leads to quite high values for the gradient steepness s. Density differences of this multitude are ill-suited for current single-material manufacturing techniques. Additive multi-material techniques, on the other hand, could approximate smooth gradients like this, e.g., using dithering.

3.3 Optimizing nonlinear fields

Section 2.3 introduces our concept for density fields with a generalization to define geometry-independent density values per vertex. This allows for the approximation of arbitrary nonlinear fields, as illustrated with the examples in Fig. 6: The Bunny is embedded in a spherical sinusoidal density function, the density in the Femur decreases from surface to core with a Gaussian slope. Tet-mesh vertices become 3D sampling positions for the 3D density field, however, gradients within each tetrahedron are still linear. Nevertheless, this piecewise linear Taylor approximation of a nonlinear field is \(C_0\) continuous everywhere (\(C_\infty \) within a tetrahedron). The accuracy of this representation is only limited by the resolution of the tetrahedral mesh, which can be specified in common tetrahedralization tools.

Fig. 6
figure 6

Examples of nonlinear density fields, sampled at vertex positions. Tetrahedralizations created with TetWild on default settings for the Bunny and with a smaller edge-length for the Femur

Fig. 7
figure 7

The rockerarm is a prominent example for an asymmetric object with rotary mount. Due to imbalance, the native center of mass (red) is not located on the rotation axis. With optimized density, our center of mass (green) is located on the rotation axis and the principle inertia momentum axis is parallel to the rotation axis

Advanced applications, specifying more than a single center of mass, may require density fields, more sophisticated than linear gradients. An approach related to the make-it-stand concept proposed the challenge to make objects spinnable [1] by moving mass centers to a specified rotation axis. This is not only a desirable criterion for toy tops or yo-yos but is also of great value in any mechanical process involving rotating movements to reduce the wear and tear of involved components. Engineering such mechanical components often comes with tight constraints on available space and does not allow for arbitrary placement of counterweights. Figure 7 illustrates an example with the rockerarm object, which is to be mounted on rotary bearings. With constant density, the native center of gravity and inertia tensor are off-axis due to the obvious asymmetry of the object.

$$\begin{aligned} \begin{aligned} d(v)&= \sin (|p-v| \cdot k)+1\\ \end{aligned} \end{aligned}$$
(5)

For this object, the optimized density field results in a center of mass located on the rotation axis along with a parallel principle inertia momentum axis. The density field is parameterized with the nonlinear density function d(v) (Eq. 5), where v is a tet-mesh vertex, p a 3D coordinate and k a scalar factor.

Results Optimizing for a specific center of mass, as in Sect. 3.2, is not trivial but possible, dependent on given constraints. Additionally fitting a principle inertia momentum axis, however, can be challenging as the density distribution for a certain center of mass may be in conflict with the optimal density for the momentum axis. A field parameterization with more degrees of freedom than ours (Eq. 5) might be more suitable for optimization but unreasonable for practical results. Our results are shown in Fig. 7 with an optimized center of mass (green). The density parameters are:

$$\begin{aligned} \begin{aligned} p = \begin{pmatrix} 0.509475 \\ -0.699066 \\ 1.328176 \end{pmatrix}\ \quad \text {and}\quad \ k = 7.853375 \end{aligned} \end{aligned}$$

The principle inertia momentum axis was met with accuracy of \(<~1^\circ \), the center of mass is actually precisely located on the specified target rotation axis.

3.4 3D printing of varying density

For some objects, we demonstrate both synthetic results as well as 3D printouts. One has to mention that 3D printing hardware for varying density is still in an early development state [8, 13, 19] and the range of available densities is limited. On recent Prusa FDM printers, however, it is possible to alter the extrusion rate while printing. The first step is to obtain the G-code for an object with a regular infill pattern. In order to approximate the optimized density field, we modify the line thickness to vary along printed segments by accordingly adjusting the relative extrusion rate in the G-code slice by slice.

Fig. 8
figure 8

Modifying the extrusion rate allows for printing density gradients. The bar on top is a cross-section of an object \(10{\times }10{\times }100\) mm in size, scanned with a photocopier. Pictures of the rockerarms (\(62.9{\times }33{\times }17.6\) mm) were taken in front of a lightsource to highlight the different density distributions. See video for live demo

Fig. 9
figure 9

2D visualization of the equivalent energy terms of Eq. 7 with an integral over the Chebyshev distances of all points in a cell or the sum over its tetrahedral fragments with density gradients

Fig. 10
figure 10

Results after 50 Lloyd relaxations: A unit-cube on the left and two Clipped-Voronoi-Diagrams [30] in the middle and on the right (Cutouts in blue). Examples a, c and e used the \(L_2\) norm to reposition their sites in each step, the examples b, d and f show results using the \(L_\infty \) norm, generating close to cube-like cells. Despite different relaxation norms, all results are visualized as \(L_2\) tessellations

Fig. 11
figure 11

Voronoi cells under the \(L_\infty \) norm before and after the relaxation. Saturation visualizes the \(L_\infty \) energy, increasing in each dimension. A centroid in a cubical cell minimizes this energy

Figure 8 shows a 3D printed example of a simple bar with increasing density. The varying amount of printed material alters the translucency of the object. The 3D printed rockeram of Fig. 7 with optimized density for an on-axis center of mass and a parallel principle inertia momentum axis leads to significantly smoother spinning as can be seen in the accompanying video.

3.5 Lloyd relaxation with the \(L_\infty \) norm

The last proposed application scenario makes use of the closed-form integral solution of measures on volumes of varying density to approach Lloyd relaxations under non-standard norms. All calculations are done on the actual shape of the Voronoi cells avoiding any voxelization, which reduces artifacts and speeds up the computation.

Lloyd’s algorithm [14] is an iterative optimization procedure that is proven to converge to Centroidal-Voronoi-Tessellations (CVT) under the \(L_2\) norm [4]. The iteration alternates two steps: I. Compute a Voronoi diagram for a given set of points. II. Reposition each point to the centroid of its Voronoi cell. This can also be formulated as an optimization task, minimizing the diagram’s global energy function.

Since the native \(L_2\) cells are all convex, the computation of new centroids is quite simple. However, in many meshing applications, \(L_p\) or even \(L_\infty \) are more desirable [12], due to their more rectangular or cubical cell shapes. For \(L_p\) norms (\(p > 2\)), the Voronoi cells are no longer always convex and the diagram becomes very impractical to handle or even generate since there is (to the best of our knowledge) no software library that is able to compute \(L_p\) or \(L_\infty \) Voronoi tessellations.

In meshing applications [12, 27] the diagram itself is actually not relevant, but only the site positions are of interest [25]. We propose a way to compute Lloyd relaxed site positions with the \(L_\infty \) metric, also called the Chebyshev distance: First, cell geometry and topology are borrowed from an \(L_2\) tessellated diagram, which comes with the convenience of convex-only cell shapes. Then we use our method and compute a cell’s mass, reinterpreted as the energy which is to be minimized by a new cell center.

Fig. 12
figure 12

\(L_\infty \) relaxation plots of the cube from Fig. 10b over 50 iterations. Left: Average movement of all cell centers in one iteration, given in percent of the optimal cell’s diagonal. Right: Average \(L_\infty \) energy of all cells, given in percent of an optimal cell’s \(L_\infty \) energy, which is why the result converges to 100%

The Energy Term For the goal to minimize the \(L_\infty \) energy within a cell, let us briefly recapitulate how the Chebyshev distance \(d_\infty \) is defined. As formulated in Eq. 6, the distance between two points p and q is the maximum of their absolute differences over all dimensions, in the 3D case xy and z:

$$\begin{aligned}&d_\infty (p,q) = \max _{k\in [x,y,z]} |q_k-p_k| \end{aligned}$$
(6)
$$\begin{aligned}&E_{\mathbf {C}} = \int _{P \in {\mathbf {C}}} \mathrm{d}_\infty (C_{\mathbf {C}}, P)\nonumber \\&\qquad \qquad = \sum _{i\in [\pm x, \pm y, \pm z]} \sum _{T\in F_i} {\mathbf {M}}_T^i \end{aligned}$$
(7)
Table 3 A practical performance comparison to octree approximations, where our method generated the reference mass properties

Equation 7 formulates the energy \(E_{\mathbf {C}}\) of a cell \({\mathbf {C}}\) as the total Chebyshev distance of all points \(P\in {\mathbf {C}}\) to the cell’s centroid \(C_{\mathbf {C}}\). However, there are infinitely many points \(P\in {\mathbf {C}}\), so the energy function can only be evaluated with a nontrivial integral over the cell volume.

As illustrated in Fig. 9 (in 2D), this integral becomes feasible as a finite sum of analytical solutions. To achieve this, a cell is split into six fragments \(F_k\) (\(k\in [\pm x, \pm y, \pm z]\)), as illustrated in Fig. 11. This effectively separates all points P within the cell with respect to their maximum difference-dimension (Chebyshev). Due to the separation into the six fragments, the \(d_\infty (C_{\mathbf {C}},P)\) distance dimension conveniently coincides with the corresponding geometric dimension k, i.e., the distance linearly increases along one of the coordinate axes. As the hull of a Voronoi cell might be complex, the six fragments are tetrahedralized using a trivial triangulation of their hull faces and the cell center itself. The inner sum in Eq. 7 accumulates masses \({\mathbf {M}}_T^k\) of all tetrahedra T in a fragment \(F_k\) as defined in Eq. 1. The Chebyshev distance is simply encoded as the density dimension along the coordinate axes for our computation. The outer sum accumulates the density- (or Chebyshev distance-) weighted volumes of the six fragments, resulting in the cell’s \(L_\infty \) energy. The cell center is finally repositioned to minimize the computed \(L_\infty \) energy using the L-BFGS-B algorithm [3, 32] for bound constrained minimization.

Fig. 13
figure 13

By increasing the depth of an octree (\(\#\) levels on the x-axis), the approximations converge against our analytic results. The plot shows the time in seconds to build and traverse the tree, the number of nodes in the tree, the mass center error \(\epsilon _C\), the mass error \(\epsilon _M\) and inertia tensor error \(\epsilon _\Theta \). Dashed lines show timings for our computation based on tets and the time it took for TetGen [26] to tetrahedralize the input

Fig. 14
figure 14

Visualization of the octrees used in Fig. 13. With increasing depth (2-8) of the tree, the approximations for mass properties converge against our analytic results based on the real mesh

Results Although cell energies are only optimized on an individual basis, the relaxation iteration also leads to a global decrease of the diagram’s energy, analogously to the \(L_2\) case. With our reformulation of the objective function, the second part of the Lloyd relaxation (repositioning of cell centers) becomes feasible for the \(L_\infty \) norm. The initialization of each iteration is still based on a computable \(L_2\) Voronoi tessellation, which turned out to be sufficient as the relaxation still converges. Considering the shape of an \(L_2\) Voronoi cell while optimizing the centers for the \(L_\infty \) energy, this optimization is not a full \(L_\infty \) relaxation but a convenient alternative. If an \(L_\infty \) tessellation was available, the relaxation would probably converge even faster and would also allow for individually oriented cells. Nevertheless, considering the alternatives, e.g., labeling underlying high-resolution voxel grids, it is an improvement in terms of both accuracy and performance.

The plots in Fig. 12 show convergence results of the cube (Fig. 10b) throughout 50 Lloyd relaxation steps. The Movement plot shows the average distance traveled by all sites (cell centroids) in the Voronoi diagram during each relaxation step. This distance is given in percent of an optimal cubical cell’s diagonal. The average cell-energy, shown in the Energy plot, is computed for each cell as illustrated in Fig. 11 by separating a cell into six fragments and accumulating the density-weighted volume. It is expressed in percent of an optimal cubical cell’s \(L_\infty \) energy. Therefore, the convergence towards 100% indicates that our cells approach the anticipated optimal cubical cell shape.

4 Discussion

This section presents the results of the proposed application scenarios for our concept. Benefits over traditional methods in terms of performance and accuracy are quantitatively discussed with numerical results. After an outlook on potential extensions and future work, we conclude with a roundup of our main contributions.

4.1 Results

As mentioned in Sect. 1.2, voxelizations or octrees are currently the most common method to approximate mass properties for objects in fields of varying density. Table 3 documents comparisons of our exact tetrahedron-based method to octrees of different depths. Our results provide the ground truth reference, to which the octree approximations are compared. Timings for the octrees include the build-up phase and traversal to compute the results. The most demanding parts in the build-up are in/out-tests, to decide if a cell is to be split again. To be comparable, we included the time to create the tet-mesh inputs for our method from basic surface meshes. Delaunay tetrahedralizations are computed with TetGen [26], using the -Y option which preserves the source mesh, so that our method and the octree have the exact same input. Both, octree and our method, are implemented in Python using vectorized NumPy arrays where possible for optimized efficiency. Although our method is well suited to be implemented in parallelized GPU code, all timings are measured on a single CPU core. The measurements show that, not only compared to the very deep but also for the small octree of only 4 levels, our method is multitudes faster even including the input tetrahedralization.

Timings and performance aside, the probably most valuable takeaway is the analytical accuracy of the results. Our method establishes actual ground truth results for mass properties under varying densities. Figure 13 plots the mass-property-errors of octree approximations (Fig. 14) converging against our results, as we increase their depth and therefore accuracy. Featured errors of mass \(\epsilon _M\), center of mass \(\epsilon _C\), and the inertia tensor \(\epsilon _\Theta \) are specified in Eq. 8.

$$\begin{aligned} \begin{aligned} \epsilon _C&= |C_\text {octree} - C_\text {tet}|\\ \epsilon _M&= \frac{|M_\text {octree} - M_\text {tet}|}{M_\text {tet}}\\ \epsilon _\Theta&= \sum _{i \in [x,y,z]} \frac{|\Theta _{\text {octree}}^i - \Theta _{\text {tet}}^i|}{|\Theta _{\text {tet}}^i|} \end{aligned} \end{aligned}$$
(8)

In theory, a voxel grid of infinite resolution or an octree of infinite depth would give correct and unbiased mass property results. We use this capacity to show that octree results converge against our analytic results by increasing their depth and accuracy. The error plots do not converge monotonically due to aliasing artifacts, for some lower levels the approximations are just more accurate by chance.

4.2 Conclusion

We propose novel application scenarios for object’s mass properties under varying densities. Easy to use analytical solutions make approximations obsolete, which are still common in recent state-of-the-art applications [1, 10, 21, 22, 29]. Our concept is fast, lightweight, easy to implement, and suitable for vectorized or parallelized frameworks. We demonstrate possible use cases where our method can be utilized straightforward: Masses, mass centers, and inertia tensors of arbitrary manifolds in given density fields are computed accurately. We formulate an optimization to determine a parameterized density field for an object and specified mass properties like a center of gravity or inertia tensor. Our proposed modification of the Lloyd relaxation is a novel \(L_{2|\infty }\) hybrid that allows us to imitate real \(L_\infty \) relaxations, which is a leap forward compared to the existing approximative alternatives. While our approach may find direct application in established research topics as meshing, spatial tessellation and simulation [9, 25], we also see great potential in the young scientific field of additive manufacturing and hope to inspire many further research [10, 29, 31].