Use quaternions instead of euler angles during optimization
Euler angles representation may be unstable in some configurations close to singular orientation. The optimization may therefore be unstable too, oscillating between two similar possible but not continuous euler angles representations. Using quaternions would prevent this singularities and ensure safe convergence.