Mid-Atlantic Developer Conference

# hypot

(PHP 4 >= 4.1.0, PHP 5, PHP 7)

hypot Länge der Hypotenuse eines rechtwinkligen Dreiecks

### Beschreibung

hypot ( float `\$x` , float `\$y` ) : float

hypot() berechnet die Länge der Hypotenuse eines rechtwinkligen Dreiecks aus den Längen der beiden Katheten bzw. den Abstand eines Punktes (`x`,`y`) vom Ursprung. Dies entspricht sqrt(x*x + y*y).

### Parameter-Liste

`x`

Länge der ersten Kathete

`y`

Länge der zweiten Kathete

### Rückgabewerte

Berechnete Länge der Hypotenuse add a note

### User Contributed Notes 2 notes

Hayley Watson
1 year ago
``` If you need a higher-dimensional diagonal length (norm), you can exploit the fact that sqrt(x*x+y*y+z*z) == sqrt(x*x+sqrt(y*y+z*z)). In other words hypot(x, y, z)==hypot(x, hypot(y, z)).To be generic about it....<?phpfunction norm(...\$args){    return array_reduce(\$args, 'hypot', 0);}?> ```
-10
robinv at ecosse dot net
15 years ago
``` A simpler approach would be to allow an arbitrary number of parameters. That would allow for whatever number of dimensions you want *and* it would be backwards compatible with the current implementation.<?phpfunction hypo() {    \$sum = 0;    foreach (func_get_args() as \$dimension) {        if (!is_numeric(\$dimension)) return -1;        \$sum += pow(\$dimension, 2);    }    return sqrt(\$sum);}print hypo();          // vector in 0 dimensions, magnitude = 0.print hypo(1);         // vector in 1 dimension,  magnitude = 1.print hypo(3, 4);       // vector in 2 dimensions, magnitude = 5.print hypo(2, 3, 6);     // vector in 3 dimensions, magnitude = 7.?> ``` 