A Geometric Approach to Trajectory Planning for Underactuated Mechanical Systems