From d3dda667b39e202ef13c6756578c987aaa1c04f8 Mon Sep 17 00:00:00 2001 From: jiaming <743192023@qq.com> Date: Sat, 15 Dec 2018 19:16:53 +0800 Subject: [PATCH] add get point to line min distance fun --- src/plugins/methodsExtend.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 }