We help IT Professionals succeed at work.

Java Trigonometry

bravotango
bravotango asked
on
592 Views
Last Modified: 2013-12-14
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?
Comment
Watch Question

Cyril JoudiehFounder, Software Engineer, Data Scientist

Commented:
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
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

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

Commented:
the sine of some angles ARE neative.

Author

Commented:
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.
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks for the solution ozo. I am headed in the right direction now!!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.