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

Using JavaFX in Swing to replace jEditorPame for HTML rendering
org.springframework.batch.item.file.FlatFileParseException:
Running Test Groups in same class parallel
How to make a number triangle java
What difference will static methods in a JAX-RS class make?
Json parsing error using Java
How to import gradle project into STS 3.7.2
How to run cbioportal tomcat war using heroku's webapp-runner.jar
Looking to write info to a file using print writer from button inputs on a simple GUI application
I cannot understand the purpose of using and not using “void”,(what does returning a value mean?" [duplicate]
How to remove “org.restlet.engine.application.StatusInfo” on JSON response
How to print stack trace without error occurance
LibGDX: Problems with getting Bounds
Timeout logs in Rivr Dialogues
freemarker template syntax spring boot
Generate ranges from list of values

Categories

HOME
pandas
cloud
deployment
cookies
google-play
layout
getelementsbytagname
yarn
rubygems
fsm
pivotal-cloud-foundry
session-variables
google-translate
vifm
adobe-analytics
vault
node-pdfkit
resize
alignment
dtrace
try-catch
transformation
code-review
object-detection
hammerspoon
cas
wpfdatagrid
maquette
buck
ejabberd-module
nouislider
microsoft-chart-controls
airconsole
atl
html5-fullscreen
wpf-controls
hot-module-replacement
neuroscience
az-application-insights
tasker
google-closure
spring-security-kerberos
total-commander
upstart
clean-architecture
typescript1.8
integrity
idisposable
yii2-extension
setter
google-perftools
ifs
pintos
root-framework
cubes
parallel-data-warehouse
xcb
android-fonts
database-optimization
file-writing
essence
dlna
bluemix-app-scan
dataview
suffix-tree
system.management
google-places
wireshark-dissector
rgeo
deis
fluid-dynamics
clipperlib
c++03
javax.mail
npapi
pick
aapt
p4java
didselectrowatindexpath
balanced-payments
srs
imdbpy
sqlperformance
flashvars
ocunit
e4x
mhtml
funscript
venn-diagram
pendrive
window-management
nsobject
android-sdk-2.1
floating
cxxtest
.nettiers
xsdobjectgen
castle-monorail
uimenucontroller
swing-app-framework
sector
spec#
data-acquisition

Resources

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