# Midpoint in line

**URL:** <https://community.cesium.com/t/midpoint-in-line/5578>\
**Category:** CesiumJS\
**Created:** [May 31, 2017, 2:24pm UTC](https://community.cesium.com/t/midpoint-in-line/5578 "2017-05-31T14:24:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fidel\_Perez-Smith](https://avatars.discourse-cdn.com/v4/letter/f/278dde/32.png) [@Fidel\_Perez-Smith](https://community.cesium.com/u/Fidel_Perez-Smith)\
**Post date:** [May 31, 2017, 2:24pm UTC](https://community.cesium.com/t/midpoint-in-line/5578/1 "2017-05-31T14:24:56Z")

</div>

Hi,

I have two points. Each is defined by lat/long/height.

I’m drawing a straight line in between them (I’m not concerned about following the surface of the earth, just a straight line is what I want).

Is it possible to calculate the midpoint between the two? Ie. Calculate the lat/long/height of the point that is in the middle of the line?

Thank you,

Fidel

[![](https://lh3.googleusercontent.com/-i9YS8zTFbPU/WS7R06kPdQI/AAAAAAABYAk/7Y3cIBfeVI0tMOID_MDYsIgAn8Z2F-urwCLcB/s1600/midpoint.png)](https://lh3.googleusercontent.com/-i9YS8zTFbPU/WS7R06kPdQI/AAAAAAABYAk/7Y3cIBfeVI0tMOID_MDYsIgAn8Z2F-urwCLcB/s1600/midpoint.png)

---

<div class="post-metadata">

**Author:** ![Rachel\_Hwang](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@Rachel\_Hwang](https://community.cesium.com/u/Rachel_Hwang)\
**Post date:** [May 31, 2017, 7:27pm UTC](https://community.cesium.com/t/midpoint-in-line/5578/2 "2017-05-31T19:27:21Z")

</div>

Hi Fidel,

This is a classic graphics math problem. To compute the midpoint between two points A and B, we an compute the vector between them by taking (B - A), normalizing to get the direction vector. Then multiplying this direction vector by magnitude of (B-A) multiplied by the fraction of the way we want to travel between them. Then you can just convert to Cartographic. Here’s the code for this: [http://cesiumjs.org/Cesium/Apps/Sandcastle/?src=Hello%20World.html&label=Showcases&gist=d290d6e52cdeec93ac14c8a0aef1a8b6](http://cesiumjs.org/Cesium/Apps/Sandcastle/?src=Hello%20World.html&label=Showcases&gist=d290d6e52cdeec93ac14c8a0aef1a8b6)

You can also use linear interpolation to get an intermediate point. Let me know if you want to discuss that method also.

Hope that helps!

- Rachel

---

<div class="post-metadata">

**Author:** ![Fidel\_Perez-Smith](https://avatars.discourse-cdn.com/v4/letter/f/278dde/32.png) [@Fidel\_Perez-Smith](https://community.cesium.com/u/Fidel_Perez-Smith)\
**Post date:** [June 1, 2017, 10:56am UTC](https://community.cesium.com/t/midpoint-in-line/5578/3 "2017-06-01T10:56:51Z")

</div>

This is perfect Rachel! Exactly what I was looking for. Thank you so much.

Could you please let me know about linear interpolation as well? I had been trying with Ellipsoid.interpolateUsingFraction() but I wasn’t getting a height component.
