orientation algorithm