add get point to line min distance fun

This commit is contained in:
jiaming 2018-12-15 19:16:53 +08:00
parent f45f7f742d
commit d3dda667b3
1 changed files with 18 additions and 0 deletions

View File

@ -46,6 +46,22 @@ export function filterNull (arr) {
return tmpArr 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) { export default function (Vue) {
Vue.prototype.deepClone = deepClone Vue.prototype.deepClone = deepClone
Vue.prototype.deleteArrayAllItems = deleteArrayAllItems Vue.prototype.deleteArrayAllItems = deleteArrayAllItems
@ -53,4 +69,6 @@ export default function (Vue) {
Vue.prototype.multipleSum = multipleSum Vue.prototype.multipleSum = multipleSum
Vue.prototype.randomExtend = randomExtend Vue.prototype.randomExtend = randomExtend
Vue.prototype.filterNull = filterNull Vue.prototype.filterNull = filterNull
Vue.prototype.getPointDistance = getPointDistance
Vue.prototype.getPointToLineDistance = getPointToLineDistance
} }