我有一个代表圆心的点 c 。在我拖动圆圈后,我希望它的y坐标 hmm 捕捉到点 a 和
到目前为止,我已经能够找到点 a 和
b
之间绘制的线。如何解决 hmm ?到目前为止,我已经能够找到点 a 和
b
之间的中间 y 值。但是,它没有考虑到点 c 的 x 值。const snapYToLine = (aY, bY) => {
const yDist = bY - aY;
return aY + (yDist * 0.5);
}
const a = { x: 10, y: 10 };
const b = { x: 50, y: 30 };
const c = { x: 20, y: 0 }; // not doing anything with this yet...
const hmm = snapYToLine(a.y, b.y); // will need to include c.x here...
console.log(hmm);
(Xc - Xa)
替换(x - Xa)
。 - Christopher Stevens