Calculate inertia tensors

This topic inspired me to experiment with calculating tensors of more complex shapes of rigid bodies (I did not find them in the Mathematica database).

For simple shapes of rigid bodies, everything works great:

MomentOfInertia[Ball[{0, 0, 0}, R]];

MomentOfInertia[Cone[{{0, 0, 0}, {0, a, 0}}, R]];

MomentOfInertia[Cylinder[{{0, -1/2, 0}, {0, 1/2, 0}}, R]];

Remark: https://mathematica.stackexchange.com/a/62895/67019 The code from here also works and gives similar results.

My question: And how to calculate the inertia tensor for more complex rigid bodies. For example, for a sector of a torus or a ring with a rectangular cross section?

This picture from SolidWorks.



2 Answers 2


Here is an example for half a torus.

r0 = 1; (*center radius*)
r1 = 0.2;(*outer radius*)
Region[ParametricRegion[{(r0 + r*Cos[θ]) Cos[ϕ], (r0 + r*Cos[θ]) Sin[ϕ], 
   r*Sin[θ]}, {{r, 0, r1}, {θ, 0, 2 π}, {ϕ, 
    0, π}}], Axes -> True]

enter image description here

The mass density is assumed to be 1. For other values you simply multiply the result by this value. The inertia tensor relative to the coordinate axes is then:

reg = ParametricRegion[{(r0 + r*Cos[θ]) Cos[ϕ], (r0 + 
       r*Cos[θ]) Sin[ϕ], r*Sin[θ]}, {{r, 0, r1}, {θ, 0, 2 π}, {ϕ,0, π}}];
tensor = Outer[Times, {x, y, z}, {x, y, z}]
NIntegrate[tensor, {x, y, z} ∈ reg]

(* {{x^2, x y, x z}, {x y, y^2, y z}, {x z, y z, z^2}} *)

(* {{0.20109, 0.00010941, 2.40669*10^-6}, {0.0000312697, 0.200579, 
  0.0000373482}, {-0.0000400759, -9.15108*10^-7, 0.00384308}} *)


The cross section is given by the terms: r*Cos[θ]and r*Sin[θ]. To change the cross section we simply need to change these terms. E.g. a quadratic cross section:

r0 = 1; 
w = 0.2;
Region[ParametricRegion[{(r0 + x1) Cos[ϕ], (r0 + x1) Sin[ϕ],
    y1}, {{x1, -w, w}, {y1, -w, w}, {ϕ, 0, π}}], Axes -> True]

enter image description here

  • 2
    $\begingroup$ How about with rectangular cross section what OP mentioned ? $\endgroup$ Dec 31, 2022 at 12:01
  • 1
    $\begingroup$ @Mariusz Iwaniuk With my info, you should be able to do that yourself. $\endgroup$ Dec 31, 2022 at 12:39
  • $\begingroup$ thanks for your attention to the issue! I think @MariuszIwaniuk asked a good question. In my opinion, there are two ways: either use parametrization formulas, or transfer geometry from SW to Mathematica. And it would be great to get analytical expressions for the moments of inertia. So, the inertia tensor for, for example, a ring with a triangular section, a polyhedron with pyramids on the bases and other similar complex shapes, the problem can be difficult to solve. Perhaps it is worth thinking in the direction that a complex body can be decomposed into a sum of simpler geometries ... $\endgroup$
    – dtn
    Dec 31, 2022 at 13:57
  • $\begingroup$ Look at my added content $\endgroup$ Dec 31, 2022 at 16:34
  • $\begingroup$ and how can i get a triangular cross-section? $\endgroup$
    – dtn
    Jan 6, 2023 at 5:35
  • According to the document of MomentOfInertia, the tensor should be
{{y^2 + z^2, -x*y, -x*z}, {-y*x, x^2 + z^2, -y*z}, {-z*x, -z*y, 
  x^2 + y^2}}
result1=Integrate[{{y^2 + z^2, -x*y, -x*z}, {-y*x, 
   x^2 + z^2, -y*z}, {-z*x, -z*y, x^2 + y^2}}, {x, y, z} ∈ 
  Ball[{0, 0, 0}, R]];
result2=MomentOfInertia[Ball[{0, 0, 0}, R]];
result1 == result2


  • For general region,
reg = RegionDifference[
   RegionProduct[Annulus[{0, 0}, {1, 2}], Line[{{0}, {1}}]], 
   Cuboid[{0, 0, 0}, {2, 2, 2}]];
Region[reg, ViewPoint -> {1, 1, 1}]
MomentOfInertia[DiscretizeRegion@reg, {0, 0, 0}]
Integrate[{{y^2 + z^2, -x*y, -x*z}, {-y*x, 
   x^2 + z^2, -y*z}, {-z*x, -z*y, x^2 + y^2}}, {x, y, z} ∈ 

enter image description here enter image description here

  • 1
    $\begingroup$ Will this algorithm be effective if we try to get the tensor in an analytical form? Without setting the geometric properties of the object in advance and get the tensor in an explicit form? $\endgroup$
    – dtn
    Dec 31, 2022 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.