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 ?)

Categories

HOME
compiler-construction
ionic-framework
wso2-am
clips
netsuite
include
lodash
dot
bookshelf.js
tizen-web-app
infragistics
windows-server
ravendb
webrequest
rascal
u-sql
export-to-csv
phaser
database-replication
interop
reverse-proxy
autoconf
tapestry
smb
opennlp
cas
filezilla
fluentvalidation
compatibility
libuv
mapbox-gl
nssegmentedcontrol
streamsets
starteam
hilbert-curve
elasticsearch-plugin
nand2tetris
password-encryption
unixodbc
flashair
upstart
fancybox-2
google-perftools
iso8601
spring-mongodb
dwscript
jquery-filter
paypal-express
player
qcustomplot
spim
qdialog
iis-arr
tarjans-algorithm
responsive-images
unity5.2.3
bigbluebutton
java.util.concurrent
id3v2
client-side-templating
valueconverter
system.net.webexception
cloud-connect
pyhdf
spring-io
anonymous-methods
hamiltonian-cycle
chuck
bitsharp
regsvr32
nsmanagedobject
jquery-ui-layout
appendto
datareader
icanhaz.js
fixed-width
user-friendly
firefox4
zend-tool
w3wp
dbisam

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App