Learning and Optimization with 3D Orientations