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?

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

Is your question about how to convert degrees to radians?

radians = degrees*pi/180

where pi = 4*atan2(1,1) = 3.141592653589793238462643383279...

radians = degrees*pi/180

where pi = 4*atan2(1,1) = 3.141592653589793238462643

the sine of some angles ARE neative.

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.

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.

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.

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

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)