我在画布上画画,我希望在另外两点之间得到一个点.我有:
let uno = {x:100, y:200};
let dos = {x: 900, y:2000};
let length = 20; //px
Run Code Online (Sandbox Code Playgroud)
如何通过距离以像素长度(从uno开始)获取uno和dos之间的点?示例中的图像

使用三角学:
function lenpoint(x1, y1, x2, y2, len) {
var dx = x2-x1,
dy = y2-y1;
var theta = Math.atan2(dy, dx);
var xp = len * Math.cos(theta),
yp = len * Math.sin(theta);
return [xp + x1, yp + y1];
}
Run Code Online (Sandbox Code Playgroud)