Optimal shapes in force fields