diff --git a/src/plugins/methodsExtend.js b/src/plugins/methodsExtend.js index 789830b..07843be 100644 --- a/src/plugins/methodsExtend.js +++ b/src/plugins/methodsExtend.js @@ -46,6 +46,22 @@ export function filterNull (arr) { return tmpArr } +export function getPointDistance (pointOne, pointTwo) { + const minusX = Math.abs(pointOne[0] - pointTwo[0]) + + const minusY = Math.abs(pointOne[1] - pointTwo[1]) + + return Math.sqrt(minusX * minusX + minusY * minusY) +} + +export function getPointToLineDistance (point, linePointOne, linePointTwo) { + const a = getPointDistance(point, linePointOne) + const b = getPointDistance(point, linePointTwo) + const c = getPointDistance(linePointOne, linePointTwo) + + return 0.5 * Math.sqrt((a + b + c) * (a + b - c) * (a + c - b) * (b + c - a)) / c +} + export default function (Vue) { Vue.prototype.deepClone = deepClone Vue.prototype.deleteArrayAllItems = deleteArrayAllItems @@ -53,4 +69,6 @@ export default function (Vue) { Vue.prototype.multipleSum = multipleSum Vue.prototype.randomExtend = randomExtend Vue.prototype.filterNull = filterNull + Vue.prototype.getPointDistance = getPointDistance + Vue.prototype.getPointToLineDistance = getPointToLineDistance }