# Why would Cesium.Cartesian3.distance() be returning a NaN?

**URL:** <https://community.cesium.com/t/why-would-cesium-cartesian3-distance-be-returning-a-nan/5887>\
**Category:** CesiumJS\
**Created:** [July 31, 2017, 3:47pm UTC](https://community.cesium.com/t/why-would-cesium-cartesian3-distance-be-returning-a-nan/5887 "2017-07-31T15:47:39Z")\
**Posts on this page:** 2\
**Page:** 1

<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, 3:47pm UTC](https://community.cesium.com/t/why-would-cesium-cartesian3-distance-be-returning-a-nan/5887/1 "2017-07-31T15:47:39Z")

</div>

**1. A concise explanation of the problem you’re experiencing.**

Trying to compute the distance between two Cartesian3 points using Cesium.Cartesian3.distance() but returning NaN

**2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.**

Sandcastle.addToolbarButton(‘Calculate Distance’, function() {

```auto
    clickPositions = removeDup(clickPositions); // Removes any duplicate values in the clickPositions array

    // Adds an if loop to check there are only two points in the array
    if (clickPositions.length = 2) {

        var distance = (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
[<img src="https://lh3.googleusercontent.com/-yMUc6waTxN8/WX9QksUsxBI/AAAAAAAAA4M/sgHGQJgc6Gc5KF40c6GjcapDFy3vC79hACLcBGAs/s320/Screen%2BShot%2B2017-07-31%2Bat%2B16.43.26.png" border="0" width="320" height="132">](https://lh3.googleusercontent.com/-yMUc6waTxN8/WX9QksUsxBI/AAAAAAAAA4M/sgHGQJgc6Gc5KF40c6GjcapDFy3vC79hACLcBGAs/s1600/Screen%2BShot%2B2017-07-31%2Bat%2B16.43.26.png)

```

```auto

```

**3. Context. Why do you need to do this? We might know a better way to accomplish your goal.**

Trying to measure the distance between two points, in order to measure the height of a building for example.

**4. The Cesium version you’re using, your operating system and browser.**

Cesium ver: 1.34, OS: MacOS Sierra, Browser: Chrome

Any help would be appreciated.

Thanks,

Chris

---

<div class="post-metadata">

**Author:** ![Gabby\_Getz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/gabby_getz/32/7838_2.png) [@Gabby\_Getz](https://community.cesium.com/u/Gabby_Getz)\
**Post date:** [August 1, 2017, 8:51pm UTC](https://community.cesium.com/t/why-would-cesium-cartesian3-distance-be-returning-a-nan/5887/2 "2017-08-01T20:51:14Z")

</div>

Hi Chris,

In the code sample you’ve supplied, you are not actually using the function. Here’s the documentation if needed: [https://cesiumjs.org/Cesium/Build/Documentation/Cartesian3.html#.distance](https://cesiumjs.org/Cesium/Build/Documentation/Cartesian3.html#.distance)

Thanks,

Gabby
