  In this paper, we characterize the sharp constant and maximizing functions
for weighted Poincar\'e inequalities. These results lead to refinements of
Hardy's inequality obtained by adding remainder terms involving \(L^p\) norms.
We use techniques that avoid symmetric rearrangement argument, simplifying the
analysis of these inequalities in both Euclidean and non-Euclidean contexts.
Specifically, this method applies to a variety of settings, such as the
Heisenberg group, various Carnot groups and operators expressed as sums of
squares of vector fields. Significant examples include the Heisenberg-Greiner
operator and the Baouendi-Grushin operator.
