Legendre transformation and analytical mechanics: a geometric approach