I have a list of positions like this.

t, x, y, z

where t is a double representing time in seconds and x, y, z is a position expressed in ECEF coordinates.

I would like to interpolate the position between points in the list and I believe I can do that part, but given two points and time, what is the formula to do the interpolation?

lets assume the Position object contains time, x, y, and z

// @param p1 - first position
// @param p2 - second position
// @param time - time to get interpolated position for
private Position interpolateECEF (Position p1, Position p2, double time) {
   // need help here
  • 1
    Possible cross posted to: stackoverflow.com/questions/43148203/… – xunilk Apr 1 '17 at 10:02
  • yes, it was. i originally posted there and a comment was made to post here – mike Apr 1 '17 at 13:51
  • 1
    Welcome to GIS SE. Do you assume linear travel and constant velocity? It should be simple linear interpolation solution. What have you tried? Use Edit. – Martin F Apr 1 '17 at 14:44
  • no, travel is not linear as it will start off linear and then make turns. essentially the path looks like a popsicle stick. velocity is not constant either and i have a velocity vector (magnitude would be speed), but that was going to be part 2 after i get this part working. i have not tried anything yet as i do not know where to begin – mike Apr 1 '17 at 15:12
  • Actually, i meant linear or constant between data points, meaning is it simple interpolation, requiring the very basic math of Matej solution below. – Martin F Apr 3 '17 at 15:18

Below is a simple implementation in Python to illustrate the concept.

class Point():
    def __init__(self,t,x,y,z):
        self.t = float(t)
        self.x = float(x)
        self.y = float(y)
        self.z = float(z)

    def __str__(self):
        return 'Point: t={},x={},y={},z={}'.format(self.t, self.x, self.y, self.z)

def interpolate(p1, p2, t):
    t_ratio = (t-p1.t)/(p2.t - p1.t)
    new_x = p1.x + t_ratio * (p2.x - p1.x)
    new_y = p1.y + t_ratio * (p2.y - p1.y)
    new_z = p1.z + t_ratio * (p2.z - p1.z)

    return Point(t, new_x, new_y, new_z)

def main():
    p1 = Point(t=100,x=10,y=20,z=30)
    p2 = Point(t=200,x=5,y=30,z=40)

    # interpolate for time 150
    p_interpolated = interpolate(p1,p2,150)

    print p_interpolated

if __name__ == '__main__':

This returns: Point: t=150.0,x=7.5,y=25.0,z=35.0.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.