Math.hypot(...args) 返回所有参数的平方和的平方根。
Math.hypot(...args)
二维情况:,三维情况:。
它常用于计算向量长度或点到原点的距离。
const hypot2 = (x, y) => Math.sqrt(x * x + y * y) const hypot3 = (x, y, z) => Math.sqrt(x * x + y * y + z * z)
Math.hypot(3, 4) // 5 Math.hypot(1, 2, 2) // 3
坐标系中的距离、向量长度、物理中的合力与速度大小等。