在HTML5畫布對象上,我必須減去距離目標點的距離,以便在同一行上給出最終目標。因此,首先我已經用畢達哥拉斯定理計算了源點和目標點之間的距離,但是我對泰勒斯定理的記憶太錯誤了,找不到最終點(在同一條線上),右邊的x和y屬性。使用HTML5畫布時,如何用偏移量計算最終點座標?
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像素的圓形節點隱藏,所以我嘗試獲得最終點。
非常感謝。 問候,