I have a doubt regarding finding Lagrangian of a body on an inclined plane.
Attached below are excerpts of 2 problems from a classical mechanics book that I am referring to.
In the above question, while calculating potential energy V, the height of the centre of mass of sphere above the ground is taken into account.
However,
In this case we see that potential energy V is simply height of body above horizontal level.
Why do we have different expression of V for these two problems?
I suppose I am lacking some concepts.




The correct expression for the potential energy regarding the mass center is
$$ V(x) = \left((s-x)\sin\theta + a\cos\theta)\right)mg $$
but $a\cos\theta m g$ is constant along the movement then
$$ V(x) =m g (s-x)\sin\theta+C_1 = -m g x\sin\theta + C_2 $$