Avatar of bravotango
bravotango
 asked on

Java Trigonometry

This is really a math problem but I am trying to get the sin for angles in compass bearings.
Azimuth starts from North and bearings are from 0 to 359 degrees. All goes well from 0 to 90 but then the results are incorrect due to the fact that java math requires angles in radians and higher angles return minus results. What would be the best solution to get around this. Should I break the compass into quadrants and return results to their specific quadrant?
Editors IDEsMath / Science

Avatar of undefined
Last Comment
bravotango

8/22/2022 - Mon
Cyril Joudieh

Even if they return minus, that does not mean anything wrong.

For SIN
SIN(180-x) = SIN(x)
SIN(180+x) = -SIN(x) of course you have to convert to radians

SIN(90-x) = COS(x)
SIN(90+x) = COS(x)
ozo

Is your question about how to convert degrees to radians?
radians = degrees*pi/180
where pi = 4*atan2(1,1) = 3.141592653589793238462643383279...
aburr

the sine of some angles ARE neative.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
bravotango

ASKER
Thanks for the comments.. I think I am on a better understanding of my problem now.
I found this comment on a very good site regarding solar problems.
The warning about trigonometric functions expecting angles expressed in radians still applies. Note that the azimuth needs to be expressed as a value between 0º and 360º, or -180º and 180º. To do this, consider that the tangent of an angle is y/x. Typically, programming languages and spreadsheets include arctangent functions that require both the x and y coordinates to be specified so the function can consider the sign of each component to determine the proper quadrant for the result.
I just need to work out how to do  this.
ASKER CERTIFIED SOLUTION
ozo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
bravotango

ASKER
Thanks for the solution ozo. I am headed in the right direction now!!