Hi Martin, Welcome to JavaRanch. The sin, cos and tan functions along with their inverts are located in the Math class. To do what you want would be:
I'm not sure what you mean by sin^(-1) == sec. The secant function is the reciprocal of the cosine so you would get it by doing something like:
All of these return doubles and take radians as their arguments. But if you have degrees the Math class also has a toRadians() method to do the conversion. You should take a look at the API docs on the Math class.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
posted 17 years ago
i have tried this before, but it doesnt work or im making something completly wrong. i want to get the degrees of elevation(0 <= a < 360) of a certain point relative to the middle of the screen. the formula is (sin a = x / r) .x is point.y - panel.getHeight()/2 . r is the distance between the middle and the point. this is my solution but im not getting a usefully value: a = 1.0 / Math.sin(Math.toRadians(x)/Math.toRadians(r)) am i on the right way? or does anyone know a better way to do this? thanks
Note that sin^(-1) != 1/sin. Generally, mathematicians use sin^(-1) to represent the inverse function of the sine function, known as the arcsine function, or in javaspeak, Math.asin. In general, Math.asin(x) != 1/Math.sin(x). Think of asin(x) as the angle between -pi/2 and pi/2 you have to take the sine of to get x. For instance, sin(45 degrees) = sqrt(2)/2, so asin(sqrt(2)/2) = 45 degrees. Note that it's only legal to pass asin() values between -1 and 1, and that you'll always get an answer back between -pi/2 (-90 degrees) and pi/2 (90 degrees). I'd recommend researching the definition of the sine and cosine functions and their inverses, and drawing pictures. You might find the problem easier if you restrict x and y to nonnegative values at first. If you're given x and r, then you'll unfortunately have two answers for your angle. One will be between 0 and pi (y is positive), and one will be between pi and 2*pi (y is negative).
The airline is called "Virgin"? Don't you want a plane to go all the way? This tiny ad will go all the way: