MomentOfInertia Plugin

Related: Calculating Inertia Tensor in CC3D and Calculating the Shape Constraint of a Cell – the Elongation Term

The MomentOfInertia plugin keeps an up-to-date tensor of inertia for every cell. Internally, it uses the parallel axis theorem to calculate the most up-to-date tensor of inertia. Although the plugin can be added directly with <Plugin Name="MomentOfInertia"/>, it is most commonly called indirectly by other plugins like LengthConstraint.

MomentOfInertia plugin gives users access (via Python scripting) to current lengths of each cell’s semiaxes. Examples in Demos/PluginDemos/MomentOfInertia demonstrate how to get lengths of semiaxes. For example, to get semiaxes lengths for a given cell, in Python we would type:

axes = self.momentOfInertiaPlugin.getSemiaxes(cell)

axes is a 3-component vector with 0th element being length of minor axis, 1st element being the length of the median axis (which is set to 0 in 2D) and 2nd element indicating the length of major semiaxis.

Note

Important: Since calculating lengths of semiaxes involves many floating point operations, it may happen (usually on hexagonal lattice) that for cells composed of 1, 2, or 3 pixels, one moment the square of one of the semiaxes may end up being slightly negative leading to NaN (not a number) length. This is due to round-off error and whenever CC3D detects a very small absolute value of the square of the length of any of the semiaxes (10-6), it sets the length of the semiaxis to 0.0 regardless of whether the squared value is positive or negative. However, it is a good practice to test whether the length of semiaxis is sane by adding a simple if statement as shown below (here we show how to test for a NaN):

if length != length:
    print("length is NaN")
else:
    print("length is a proper floating point number")