【发布时间】:2017-07-08 19:36:22
【问题描述】:
在 HTML5 画布对象上,我必须从目标点减去一段距离,才能在同一行上给出最终目标。
所以,首先我用勾股定理计算了源点和目标点之间的距离,但是我对泰勒斯定理的记忆太差了,无法找到具有正确 x 和 y 属性的最终点(在同一条线上) .
function getDistance (from, to){
return Math.hypot(to.x - from.x, to.y - from.y);
}
function getFinalTo (from, to, distanceToSubstract){
//with Pythagore we obtain the distance between the 2 points
var originalDistance = getDistance(from, to);
var finalDistance = originalDistance - distanceToSubstract;
//Now, I was thinking about Thales but all my tries are wrong
//Here some of ones, I need to get finalTo properties to draw an arrow to a node without
var finalTo = new Object;
finalTo.x = ((1 - finalDistance) * from.x) + (finalDistance * to.x);
finalTo.y = ((1 - finalDistance) * from.y) + (finalDistance * to.y);
return finalTo;
}
确实,箭头被半径约100像素的圆形节点所隐藏,所以我尝试得到最终点。
非常感谢。 问候,
【问题讨论】:
标签: javascript html5-canvas geometry