Measuring the distance if terrain is ON

Dear Team,
I’m trying to measure the distance of the given two points it provides the correct result but if the terrain is on then the length should be changed in hilly area’s but still, it’s providing the same distance. Is there any other way to get the distance between two points if the terrain is on? My code is given below:-

var startPoint = Cesium.Cartographic.fromDegrees(
cartesianStartNew[0].trim(),
cartesianStartNew[1].trim(),
positions[0].height
);
var endPoint = Cesium.Cartographic.fromDegrees(
cartesianEndNew[0].trim(),
cartesianEndNew[1].trim(),
positions[1].height
);
var surfacedistance = new Cesium.EllipsoidGeodesic(startPoint, endPoint);
Math.round(surfacedistance.surfaceDistance) + ’ meter’;

Thanks In advance

@Shashi

Based on the information that you’ve provided, it seems like you are looking for the distance between two points on a terrain. Is that correct? If so, I recommend using Cesium ion SDK.

Cesium ion SDK has a measurement toolkit that can be used for your application. To the best of my knowledge, CesiumJS does not support the feature that you are looking for. Do other community members have suggestions or a potential workaround?

-Sam

Thanks, but I guess Cesium ion SDK is paid. Is there any open source way to achieve this task in cesium?

@Shashi

That’s correct, Cesium ion SDK is not free. As I mentioned above, I do not think that there is a simple way to achieve this functionality in CesiumJS.

One workaround might be to string together multiple lines that are set on the surface of the terrain and add up their length. Thus you would loop through all startPoint and endPoint values for each line and add them to a totalSurfaceDistance variable.

var totalSurfaceDistance = 0;

...

//some sort of loop
  totalSurfaceDistance += new Cesium.EllipsoidGeodesic(startPoint, endPoint);

Let me know if you have any other questions or concerns. I am curious to hear your thoughts.

-Sam

@sam.rothstein
but I’ve only two points (it creating a big line in hilly area) and it’s not possible to iterate it.
Thanks

1 Like

@Shashi

One idea is to interpolate between the two points that you already have. For each point that you add using linear interpolation, you can update its altitude based upon your terrain data.

Linear interpolation - Wikipedia.

Next, you can measure and add the distance between each pair of points. This would yield a much more accurate measurement. In addition, you can always increase the number of sample points to produce a more accurate result. This is just one solution, input from the community would be welcomed!

-Sam

1 Like

@sam.rothstein
Thanks for your suggestion. Definitely, I’ll try and let u know.

1 Like

@Shashi

Great - keep me posted!

-Sam