Convert geocentric distance from center of earth to geocentric altitude

My naive way of doing this would be to convert the geodetic to cartesian (ECEF) coordinates, scale them until they are on the Earth ellipsoid and the distance between the original and scaled coords would be the geocentric height above ellipsoid. But this involves writing a bit of code to do the scaling, so if you think this is a useful approach then I can paste the scaling code that I use (which uses the WGS 84 ellipsoid).