wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes sin(), cos(), & tan() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "sin(), cos(), & tan()" Watch "sin(), cos(), & tan()" New topic
Author

sin(), cos(), & tan()

Mike Cunningham
Ranch Hand

Joined: Nov 14, 2000
Posts: 129
In the Mike Meyer's Passport to Java it states:
The trig functions sin(), cos(), & tan(), all return a double value in radians, not degrees. You can use the method toDegrees() to convert the result.
When someone is looking for the value of something using one of these functions....are they looking for an answer in radians or degrees? Also, what's the benefit of being able to convert it to the other type of value?
- Mike
Jim Hall
Ranch Hand

Joined: Nov 29, 2001
Posts: 162
These functions do not return a radian value. They return a double value which represents the ratio of sides of a right triangle. The arguments to the methods must be in radians.
sin = o/h
cos = a/h
tan = o/a
where
o = length of opposite side
a = length of adjacent side
h = length of hypotenuse side
The methods asin(), acos(), atan() return a double value in radians that represents the corresponding angle. This number can then be converted into degrees using toDegrees().
Mike Cunningham
Ranch Hand

Joined: Nov 14, 2000
Posts: 129
So, if I was asked to give the cos() value for the following variable:

...which would be correct:

- Mike
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Mike,
Radians represent angular units of measurment based on the value of PI for measuring circles and arcs.
This physics presentation gives a bit of an explanation for their use.
Radians are commonly used in calculations with results being converted to degrees. Astronomers commonly convert between degrees and radians.
If you see an answer to a trig question that shows a result of 30.5 or 280.0 then you'll know that choice is incorrect; radians values won't exceed PI.
Hope that helps.


------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Co-author Mike Meyers' Java 2 Certification Passport


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Doubt you'll see a question that would ask you to compute a cos() or sin() value except on a physics exam
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Co-author Mike Meyers' Java 2 Certification Passport
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

Mike:
The answer would be:
System.out.println(Math.sin(angle));
// = 1 this represents a ratio as Jim pointed out.
That doesn't mean that your second println stmt would fail.
Its just a magic with numbers. Your code doesn't deal with
units, its just us humans. So, your second stmt will take an input of 1 (radian) and convert it to degrees and output that
value which would be 57.??? (degrees).
regds.
- satya
ps:
Wasn't there a similar bug in some spaceship launch that
caused a mishap. Confusion between degrees and radians
or was it units...

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sin(), cos(), & tan()