# Distance between cartesian points

**URL:** <https://community.cesium.com/t/distance-between-cartesian-points/146>\
**Category:** CesiumJS\
**Created:** [November 26, 2012, 5:32pm UTC](https://community.cesium.com/t/distance-between-cartesian-points/146 "2012-11-26T17:32:22Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Christopher\_Baxter](https://avatars.discourse-cdn.com/v4/letter/c/a4c791/32.png) [@Christopher\_Baxter](https://community.cesium.com/u/Christopher_Baxter)\
**Post date:** [July 31, 2017, 9:15pm UTC](https://community.cesium.com/t/distance-between-cartesian-points/146/8 "2017-07-31T21:15:48Z")

</div>

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:

```auto
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)));
}

```

```auto

```

```auto

```

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”);  
}

```auto

```

```auto

```

[![](https://lh3.googleusercontent.com/-TuNfpcMGMF8/WX-dnqJ8QeI/AAAAAAAAA4g/b3ZHeY_ALJgpAa-jQzaiTEXZjgAw6ijlQCLcBGAs/s320/Screen%2BShot%2B2017-07-31%2Bat%2B22.11.35.png)](https://lh3.googleusercontent.com/-TuNfpcMGMF8/WX-dnqJ8QeI/AAAAAAAAA4g/b3ZHeY_ALJgpAa-jQzaiTEXZjgAw6ijlQCLcBGAs/s1600/Screen%2BShot%2B2017-07-31%2Bat%2B22.11.35.png)

```auto

```

```auto

```

Any help you can give would be greatly appreciated.

```auto

```

```auto

```

Thanks,

```auto

```

Chris

```auto

```

---

_[View the full topic](https://community.cesium.com/t/distance-between-cartesian-points/146)._
