Hi All,
I came across this post while looking for an algorithm to calculate the distance between two Cartesian points in Cesium.
However, the function is currently returning ‘NaN’ and not the distance between the two points.
Do you have any idea why it would be doing this?
See code below:
function calculateDistance(p1, p2) {
return Math.sqrt(Math.pow((p1.x - p2.y), 2) + Math.pow((p1.y - p2.y) + Math.pow((p1.z - p2.z), 2)));
}
if (clickPositions.length === 2) {
var distance = calculateDistance(new Cesium.Cartesian3.fromArray(clickPositions[0]), new Cesium.Cartesian3.fromArray(clickPositions[1]));
console.log("Distance: " + distance);
confirm("First point is: " + clickPositions[0] +
"\nSecond Point is: " + clickPositions[1] +
"\nDistance: " + distance);
} else {
confirm(“You have clicked on more than two points”);
}
Any help you can give would be greatly appreciated.
Thanks,
Chris