API Reference › Math › Math.hypot
method

Math.hypot

Math.hypot(x, y) -> fixed

Returns sqrt(x*x + y*y) — the length of the 2D vector (x, y), or equivalently the hypotenuse of a right triangle with those legs. It is the one-call form for a magnitude and reads more clearly than spelling out the squares and root. To normalize a vector, divide each component by its Math.hypot.

Example

program Demo {
  handler Step phase Update {
    let length = Math.hypot(velocity_x, velocity_y)
  }
}
← All symbols