返回两点之间的距离

5年以前  |  阅读数:367 次  |  编程语言:JavaScript 

返回两点之间的距离。

使用Math.hypot()计算两个点之间的欧氏距离。

const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
// distance(1,1, 2,3) -> 2.23606797749979

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8