Spacecraft attitude motion planning using gradient-based optimization