答案 0 :(得分:1)
你去了:
var P1 = {x: 10, y: 5},
P2 = {x: 8, y: 4},
PM = {x: 2, y: 5};
function distance(source, target1, target2) {
var zaehler = Math.abs((target2.x - target1.x)*(target1.y - source.y) - (target1.x - source.x)*(target2.y - target1.y));
var nenner = Math.sqrt(Math.pow(target2.x - target1.x, 2) + Math.pow(target2.y - target1.y, 2));
return zaehler/nenner;
}
console.log(distance(PM, P2, P1) === distance(PM, P1, P2));