I wish to travel in 3 dimensions from the a start to a target position, a given distance.
sx and sy are the x and y coordinates of the start tx and ty are the x and y coordinates of the target rx and ry are the resulting mid way coordinates 'dist' is the distance to travel dist_between = sqrt((sx - tx) ^ 2 + (sy - ty) ^ 2) ratio = (dist_between - dist) / dist_between; rx += (tx + ratio * (sx - tx)) - sx; ry += (ty + ratio * (sy - ty)) - sy;
Will this scale to 3D as follows?
sx, sy and sz are the x, y and z coordinates of the start tx, ty and tz are the x, y and z coordinates of the target rx, ry and rz are the resulting mid way coordinates 'dist' is the distance to travel dist_between = sqrt((sx - tx) ^ 2 + (sy - ty) ^ 2 + (sz - tz) ^ 2) ratio = (dist_between - dist) / dist_between; rx = sx + (tx + ratio * (sx - tx)) - sx; ry = sy + (ty + ratio * (sy - ty)) - sy; rz = sz + (tz + ratio * (sz - tz)) - sz;