We consider the problem P curve of minimizing TeX for a planar curve having fixed initial and final positions and directions. Here ¿ is the curvature of the curve with free total length l. This problem comes from a 2D model of geometry of vision due to Petitot, Citti and Sarti. Here we will provide a general theory on cuspless sub-Riemannian geodesics within a sub-Riemannian manifold in SE(d), with d¿=¿2, where we solve for their momentum in the general d-dimensional case. We will explicitly solve the curve optimization problem P curve in 2D (i.e. d¿=¿2) with a corresponding cuspless sub-Riemannian geodesic lifted problem defined on a sub-Riemannian manifold within SE(2). We also derive the solutions of P curve in 3D (i.e. d¿=¿3) with a cor...