Contraction-Expansion Analysis Module
The Contraction-Expansion module quantifies spatial dynamics of movement patterns by analyzing how trajectories expand and contract in space over time.
Spatial movement analysis examines how body segments or markers change their relative positions during movement. The module provides:
- 2D/3D area calculations: geometric area enclosed by trajectory points
- Volume analysis: 3D spatial volume changes
- Expansion-contraction rates: temporal derivatives of spatial measures
Algorithms Details
2D Area computation
The 2D implementation uses the Shoelace formula 1 for polygon area computation:
3D Volume computation
Calculates 3D volume using tetrahedron volume decomposition:
-
Divide the 3D shape into tetrahedra
For a polyhedron defined by vertices \( \{p_i\}_{i=0}^n \), partition it into a set of tetrahedra \(\mathcal{T} = \{ (p_0, p_{i}, p_{j}, p_{k}) \}\). -
Calculate each tetrahedron volume using the scalar triple product
For tetrahedron with vertices \(p_0, p_1, p_2, p_3 \in \mathbb{R}^3\)
or equivalently:
-
Sum volumes with appropriate signs
The total polyhedron volume is obtained as:
where the sign of each \(V_{\text{tetra},k}\) depends on the orientation of the vertices.
Performance Optimization
Numba JIT Compilation
The module uses Numba's Just-In-Time compilation for performance.
Note
Numba introduces compilation time on first use, but caches compiled functions for subsequent calls.
This approach grants 10-100x speedups over pure Python, avoiding overhead in critical loops.
@jit(nopython=True, cache=True)
def _area_2d_fast(points):
# Ultra-fast computation with compiled code
pass
Memory Efficiency
The implementation is optimized for memory efficiency by using in-place calculations, minimizing temporary arrays, and leveraging efficient array operations.
Limitations & Considerations
- Assumes meaningful geometric shapes from selected points.
- Requires consistent point topology across frames.
- May not capture the full spatial complexity of movement.
- Performance depends on point selection strategy.
- Always consider the movement context when interpreting results.
- Normalize for subject/task differences when appropriate.
References
-
TODO ↩