Terrain height above WGS84

Hi

I want to click points on the map and join them with a polyline.
At the same time i want to create another set of points 10 meters above the previous set and join them with a polyline.

Am i right in assuming that the height obtained by using the following methods gives height above the reference ellipsoid ?
How can i find the terrain height (Above/below the reference ellipsoid)…
Code follows…
const viewer = new Cesium.Viewer(“cesiumContainer”);

var scene = viewer.scene;

scene.camera.setView({
destination: Cesium.Cartesian3.fromDegrees(2.3488, 48.8534, 450)
});

var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);

handler.setInputAction(function onLeftClick(movement) {
// Method 1
console.log(“############################################”);
console.log(“Method 1”);
console.log(“############################################”);
var ray1 = scene.camera.getPickRay(movement.position);
var cartesian1 = scene.globe.pick(ray1, scene);
var cartographic1 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(cartesian1);
var longitude1 = Cesium.Math.toDegrees(cartographic1.longitude);
var latitude1 = Cesium.Math.toDegrees(cartographic1.latitude);
var altitude1 = cartographic1.height;
console.log("Cartesian: " + cartesian1);
console.log("Cartographic: " + cartographic1);
console.log("Longitude: " + longitude1);
console.log("Latitude: " + latitude1);
console.log("Altitude: " + altitude1);

// Method 2
console.log("############################################");
console.log("Method 2");
console.log("############################################");
var ellipsoid2 = scene.globe.ellipsoid;
var cartesian2 = viewer.camera.pickEllipsoid(movement.position, ellipsoid2);
var cartographic2 = ellipsoid2.cartesianToCartographic(cartesian2);
var longitude2 = Cesium.Math.toDegrees(cartographic2.longitude);
var latitude2 = Cesium.Math.toDegrees(cartographic2.latitude);
var altitude2 = scene.globe.getHeight(Cesium.Ellipsoid.WGS84.cartesianToCartographic(cartesian2));
console.log("Cartesian: " + cartesian2);
console.log("Cartographic: " + cartographic2);
console.log("Longitude: " + longitude2);
console.log("Latitude: " + latitude2);
console.log("Altitude: " + altitude2);

}, Cesium.ScreenSpaceEventType.LEFT_CLICK
);

I assume terrain height is only available wrt WGS84 and not in the ECEF frame (as seen in the above code)
Therefore maybe we should convert everything to ECEF.

The following functions may be useful…

function getGroundAltitude(position_ecef) {//Returns height of WGS Ellipsoid in ECEF
var ground_altitude = scene.globe.getHeight(Cesium.Ellipsoid.WGS84.cartesianToCartographic(position_ecef));
return ground_altitude;
}

var position = Cesium.Cartesian3.fromDegrees(longitude, latitude, 0);//Returns position in ECEF frame
groundAltitude = getGroundAltitude(position);//Returns height of ellipsoid wrt ECEF coordinate system

var HeightAboveEllipsoid = altitude1 - groundAltitude;

Even sampleTerrainMostDetailed doesn’t return any reasonable value of height.
Height is always negative (Even on mount everest).
So either the API is wrong or my usage is wrong

Sand castle code is attached.
const viewer = new Cesium.Viewer(“cesiumContainer”);
const terrainProvider = await Cesium.createWorldTerrainAsync();

var scene = viewer.scene;

scene.camera.setView({
destination: Cesium.Cartesian3.fromDegrees(2.3488, 48.8534, 450)
});

var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);

handler.setInputAction(function onLeftClick(movement) {
// Method 1
console.log(“############################################”);
console.log(“Method 1”);
console.log(“############################################”);
var ray1 = scene.camera.getPickRay(movement.position);
var cartesian1 = scene.globe.pick(ray1, scene);
var cartographic1 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(cartesian1);
var longitude1 = Cesium.Math.toDegrees(cartographic1.longitude);
var latitude1 = Cesium.Math.toDegrees(cartographic1.latitude);
var altitude1 = cartographic1.height;
console.log("Cartesian: " + cartesian1);
console.log("Cartographic: " + cartographic1);
console.log("Longitude: " + longitude1);
console.log("Latitude: " + latitude1);
console.log("Altitude: " + altitude1);

// Method 2
console.log("############################################");
console.log("Method 2");
console.log("############################################");
var ellipsoid2 = scene.globe.ellipsoid;
var cartesian2 = viewer.camera.pickEllipsoid(movement.position, ellipsoid2);
var cartographic2 = ellipsoid2.cartesianToCartographic(cartesian2);
var longitude2 = Cesium.Math.toDegrees(cartographic2.longitude);
var latitude2 = Cesium.Math.toDegrees(cartographic2.latitude);
var altitude2 = scene.globe.getHeight(Cesium.Ellipsoid.WGS84.cartesianToCartographic(cartesian2));
console.log("Cartesian: " + cartesian2);
console.log("Cartographic: " + cartographic2);
console.log("Longitude: " + longitude2);
console.log("Latitude: " + latitude2);
console.log("Altitude: " + altitude2);

//Method 3
var position1 = Cesium.Cartesian3.fromDegrees(longitude1, latitude1, 0);
var position2 = Cesium.Cartesian3.fromDegrees(longitude2, latitude2, 0);
const positions = [
Cesium.Cartographic.fromDegrees(longitude1, latitude1),
Cesium.Cartographic.fromDegrees(longitude2, latitude2)
];
const updatedPositions = Cesium.sampleTerrainMostDetailed(terrainProvider, positions, true);//
console.log(“Terrain ht wrt what ?:” + positions[0].height);
console.log(“Terrain ht wrt what ?:” + positions[1].height);

//Method 4
var wgs_alt1 = scene.globe.getHeight(Cesium.Ellipsoid.WGS84.cartesianToCartographic(position1));
var wgs_alt2 = scene.globe.getHeight(Cesium.Ellipsoid.WGS84.cartesianToCartographic(position2));
console.log(“Terrain ht wrt what ?:” + wgs_alt1);
console.log(“Terrain ht wrt what ?:” + wgs_alt2);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK
);