FEM for Rigid Body Dynamics: Quaternion-based Rotation Handling and Inertia Tensors
Methods for representing rotations with quaternions and handling inertia tensors in FEM rigid body simulations.
Basic Equations of Rigid Body Dynamics#
Accurately describing the motion of rigid bodies is essential in Fluid-Structure Interaction (FSI) analysis or Discrete Element Method (DEM) simulations. A rigid body is an object without deformation, where the distance between any two points always remains constant.
The velocity of an arbitrary particle within a rigid body is decomposed as follows:
Where is the velocity of the center of mass, is the angular velocity, and is the displacement vector from the center of mass to particle .
Linear Momentum and Angular Momentum#
Total linear momentum from Newton's second law is:
Where is the total mass. The acceleration of the center of mass is:
Total angular momentum is:
Where is the inertia tensor and is the total torque.
Inertia Tensor#
The inertia tensor relative to the center of mass is:
Extending to a continuum:
Where is the identity tensor, and is the outer product.
When an object rotates, the inertia tensor is transformed by the orientation matrix .
Where is the initial inertia tensor in the body frame, which only needs to be calculated once at the start of the simulation.
Rotation Representation Using Quaternions#
Representing rotation with Euler angles causes the gimbal lock problem. To avoid this, quaternions are used.
A quaternion consists of a scalar part and a vector part.
A rotation by an angle about a unit axis is:
The composite rotation of two quaternions and is expressed as a product.
Using this, the orientation matrix is explicitly expressed in terms of quaternion components.
The time derivative of a quaternion is linked to the angular velocity .
FEM Discretization and Tetrahedral Shape Functions#
When discretizing the displacement field of a rigid body in FEM, the shape functions of a tetrahedral element are:
Where are dimensionless barycentric coordinates and satisfy the condition .
In linear tetrahedral elements, displacement interpolation is:
Applying rigid body constraints reduces the degrees of freedom to 6 (3 linear + 3 rotational).
Python Implementation Example#
import numpy as np
class RigidBody:
def __init__(self, mass, I_body):
self.M = mass
self.I0 = I_body # Body frame inertia tensor (3x3)
self.x_cm = np.zeros(3) # Center of mass position
self.v_cm = np.zeros(3) # Center of mass velocity
self.q = np.array([1., 0., 0., 0.]) # Quaternion (w, x, y, z)
self.omega = np.zeros(3) # Angular velocity
def quaternion_to_rotation(self):
w, x, y, z = self.q
return np.array([
[1-2*(y**2+z**2), 2*(x*y - w*z), 2*(x*z + w*y)],
[2*(x*y + w*z), 1-2*(x**2+z**2), 2*(y*z - w*x)],
[2*(x*z - w*y), 2*(y*z + w*x), 1-2*(x**2+y**2)]
])
def inertia_world(self):
R = self.quaternion_to_rotation()
return R @ self.I0 @ R.T
def step(self, F_ext, tau_ext, dt):
# Linear motion integration
a_cm = F_ext / self.M
self.v_cm += a_cm * dt
self.x_cm += self.v_cm * dt
# Rotational motion integration
I_world = self.inertia_world()
alpha = np.linalg.solve(I_world, tau_ext - np.cross(self.omega, I_world @ self.omega))
self.omega += alpha * dt
# Quaternion update
omega_q = np.concatenate([[0.], self.omega])
q_dot = 0.5 * quaternion_multiply(omega_q, self.q)
self.q += q_dot * dt
self.q /= np.linalg.norm(self.q) # Normalize unit quaternion
def quaternion_multiply(q1, q2):
w1, x1, y1, z1 = q1
w2, x2, y2, z2 = q2
return np.array([
w1*w2 - x1*x2 - y1*y2 - z1*z2,
w1*x2 + x1*w2 + y1*z2 - z1*y2,
w1*y2 - x1*z2 + y1*w2 + z1*x2,
w1*z2 + x1*y2 - y1*x2 + z1*w2
])Practical Considerations#
1. Forgetting Quaternion Normalization
As numerical integration repeats, can occur, causing the rotation matrix to become non-orthogonal. q /= norm(q) must be performed at every time step.
2. Inertia Tensor Coordinate System Confusion is defined in the body-fixed coordinate system (body frame). If torque was calculated in the world frame, it must be applied after conversion to .
3. Time Step Selection Numerical stability is guaranteed only when the condition (similar to the CFL condition) is satisfied for the maximum natural frequency of the rigid body. Higher speed rotating objects require smaller .
4. Quaternion Interpolation (SLERP) When interpolating between two orientations, Spherical Linear Interpolation (SLERP) should be used instead of Linear Interpolation (LERP) to ensure constant velocity rotation.
Combining rigid body dynamics and FEM is the basis for FSI, DEM, and multi-body dynamics simulations. Proper implementation of quaternion-based rotation representation allows stable simulation of arbitrary 3D rotations without gimbal lock.
Tweak the axis and ω to verify quaternion rotation has no gimbal lock.
주황 화살표가 회전축. 사원수 q를 직접 곱해 매 프레임 큐브를 회전시킨다 — 짐벌락 없이 안정.
Share if you found it helpful.