SampleHeightMostDetailed misunderstood or mistake?

Running Cesium for Unity 1.13.1

In my tests I run a whole lot of raycast tests to find the Unity coordinates position of the ground to place objects, and I calculate them back to wgs84 elevation values to store them along their lat/lon geo position

I thought to replace these ray casts by SampleHeightMostDetailed, avoiding the need to bring the camera to the area to have rendered tiles for the ray cast.

To Isolate the test I have a simple setup with a cube.
The cubes position is Lat:32.0225895910763 Lon:34.7422150351583 H:30

An I attached a simple script to the cube :

using System.Collections;
using System.Collections.Generic;
using CesiumForUnity;
using Unity.VisualScripting;
using UnityEngine;

public class elevationtest : MonoBehaviour
{
public Cesium3DTileset tileSet = null;
public async void Start()
{
Unity.Mathematics.double3 positions = new Unity.Mathematics.double3[1];
positions[0].x = 32.0225895910763;
positions[0].y = 34.7422150351583;
positions[0].z = 0;
CesiumSampleHeightResult hr = await tileSet.SampleHeightMostDetailed(positions);
if (hr.longitudeLatitudeHeightPositions.Length > 0)
{
Debug.Log(“Elevation found Lat:” + hr.longitudeLatitudeHeightPositions[0].x + " Lon:" + hr.longitudeLatitudeHeightPositions[0].y + " Elevation:" + hr.longitudeLatitudeHeightPositions[0].z);
}
}
}

which gives me as debug.log : Elevation found Lat:32.0225895910763 Lon:34.7422150351583 Elevation:5.95650578786281

The cubes H is set to 30 and SampleHeightMostDetailed return 5.95

Did I not get the concept of SampleHeightMostDetailed right ? Or is there an issue in the calculation ?

Thanks !

Hi @Claude_V,

I’ll copy and paste my response from the Github issue you had opened here. Let’s keep discussing here if you have additional questions or concerns. :smile:

The height returned by SampleHeightMostDetailed is the height of the point above the WGS84 ellipsoid, which is the ellipsoid model used by Cesium for Unity. This is not necessary equal to the height above the terrain. So that could be one source of the difference.

The second is that SampleHeightMostDetailed samples the terrain at the highest level of detail. From your screenshot, it looks like the terrain is at a lower level of detail, so the cube will look misaligned. I don’t know what settings you’re using on Cesium World Terrain, but you may want to lower the Maximum Screen Space Error so that higher levels of detail are prompted to load.

Janine,

Sorry about this … yes. I got the GitHub one … and the mistake is just the order or Lat and Lon

I mixed it up (again) as the inspector Shows Lat Lon H while the Cesium functions use Lon Lat H in the x, y, z

Thanks for the help !

Claude

1 Like

No worries @Claude_V, I’m glad you were able to find the source of the error! :blush: