### 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);

### Related Links

Java IOException when deploying war file in wildfly 8

Why I must cast to Generic Type T even if I know it returns correctly?

register log4j 1.x as MXBean in Spring

What is the difference between direct initialization of class member vs doing it within a method?

JAX-RS web service is working on GlassFish Server 4.0 but not working on Tomcat

How To insert Gujarati in TextBox via Spring Hibernate in database?

gcm_defaultSenderId can't be resolved

Does jspInit() run only once?

Reading standard input via command line java

Rendering multiple lines through click and unclick libgdx java

Separating variables/arrays from an expression, and deleting duplicates?

execution of task in java within specified time

Why Does (a) print (0)?

Get other query columns with Parse

Java create file if does not exist

Android google ads error (null reference ?)