Optimal shape and motion planning for dynamic planar manipulation