# Math.hypot

# 简介

Math.hypot(...args) 返回所有参数的平方和的平方根。

# 定义

二维情况:,三维情况:

它常用于计算向量长度或点到原点的距离。

# JS 实现

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

# 应用

坐标系中的距离、向量长度、物理中的合力与速度大小等。