Спасибо, друзья, всё получилось. Вот такой код у меня вышел:
function lerp(a, b, t) {
var p = {};
p.x = (1 - t) * a.x + t * b.x;
p.y = (1 - t) * a.y + t * b.y;
return p;
}
function len(p1, p2) {
var p = {};
p.x = p2.x - p1.x;
p.y = p2.y - p1.y;
return Math.sqrt(p.x * p.x + p.y * p.y);
}
var path = [
{x: 975, y: 4880},
{x: 1375, y: 4880},
{x: 1375, y: 4480},
{x: 975, y: 4480}
];
var pathSegments = [];
var pathLength = 0;
var percent = .35;
for (var i = 0; i < path.length - 1; i += 1) {
pathSegments.push({
p1: path[i],
p2: path[i + 1],
len: len(path[i], path[i + 1])
});
pathLength += pathSegments.slice(pathSegments.length - 1, pathSegments.length)[0].len;
}
var needLength = pathLength * percent;
var pathTail = needLength;
var findSeg = 0;
for (var j = 0; j < pathSegments.length; j += 1) {
if (needLength >= pathSegments[j].len) {
needLength -= pathSegments[j].len;
} else {
findSeg = j;
break;
}
}
var tailPercent = needLength / pathSegments[findSeg].len;
console.log(lerp(pathSegments[findSeg].p1, pathSegments[findSeg].p2, tailPercent));