### java

#### How can calculate the length and angle of the hypotenuse of a rectangle?

```Given the length of the sides (height width) of a rectangle, I want to calculate the degrees of the hypotenuse going from one corner to another, as well as it's length (pythagorean theorem). How can I write this in java without "manually implementing the algorithms", having trouble finding the methods I'm looking for?
```
```Given width w and height h, the length of the diagonal is given by
Math.sqrt(w*w+h*h) // pythagoras
Or you can use Math.hypot(w,h) to do this for you.
The angle of the diagonal can be calculated by
Math.atan(h/w) // arc tan in radians
You could also use the alternative arc tan function, atan2, but that only matters if you need the result to be returned in a particular range.
To convert from radians to degrees, you can use Math.toDegrees.
```
```You should use:
org.apache.commons.math3.analysis.function.Atan atan = org.apache.commons.math3.analysis.function.Atan();
double angle = atan.value(height/width);
org.apache.commons.math3.analysis.function.Sqrt sqrt = org.apache.commons.math3.analysis.function.Sqrt();
double length = sqrt.value(height*height+width*width);```

### Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization