Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mike Cunningham
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, if I was asked to give the cos() value for the following variable:

...which would be correct:

- Mike
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic