Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
hypot() function in PHP
The hypot() function is used to calculate the hypotenuse of a right-angle triangle. It returns the length of the hypotenuse as a float. In a right-angled triangle, the hypotenuse is the longest side opposite to the right angle.
Syntax
hypot(a, b)
Parameters
a − Length of first side (numeric value)
b − Length of second side (numeric value)
Return Value
The hypot() function returns the length of the hypotenuse as a float value.
Example
Here's how to calculate hypotenuse for different triangles −
<?php
echo "Triangle 1: " . hypot(3, 4) . "<br>";
echo "Triangle 2: " . hypot(5, 12) . "<br>";
echo "Triangle 3: " . hypot(8, 15) . "<br>";
echo "Triangle 4: " . hypot(7, 24) . "<br>";
?>
Output
Triangle 1: 5 Triangle 2: 13 Triangle 3: 17 Triangle 4: 25
Practical Application
Calculate the diagonal length of a rectangle −
<?php
$length = 6;
$width = 8;
$diagonal = hypot($length, $width);
echo "Rectangle diagonal: " . $diagonal;
?>
Output
Rectangle diagonal: 10
Conclusion
The hypot() function provides an efficient way to calculate hypotenuse length using the Pythagorean theorem. It's useful for geometry calculations, distance measurements, and mathematical applications.
Advertisements
