Is there any way that I can get the sin(), cos() and tan() functions to return an angle? For example, like when you press 2nd then sin on a calculator. Or should I use different functions?

7
Contributors
13
Replies
14
Views
8 Years
Discussion Span
Last Post by mvmalderen
Featured Replies
• 1

Hard time converting radians to angles?

Hard time converting radians to angles?

lol

I am new at this. I am trying to make a little top down 2D game where the character rotates towards the mouse. Got any ideas?

So, I think the previous post was alluding to the fact that:

Hope that helps?

i belive what you are looking to use are the acos(), asin(), and atan() functions.

for instance: tan() returns the ratio of the sides (y/x or opposite/adjacent) when given the angle in radians as the argument .... whereas atan() returns the angle in radians, when given the ratio of the sides ( y/x or opposite/adjacent) as the argument.

('arctan' -- called 'atan' here -- is the inverse function of 'tan'. it is the one that is actually used when you use the 2nd key on your calculator in conjunction with 'tan'. And as mentioned, angles are in radians. to convert to degrees, muliply the radian value by 180/pi)

 the functions are called as "atan"... not "arctan" as i originally typed. sorry[/edit]

.

Thank You!!!

Yes that does help thank you!

What header do I use for arcsin()?

sorry, i made a typing mistake .. in C/C++ the functions are actually called as "asin()", "acos()" and "atan()"

the header is still the same <math.h> (aka <cmath>)

.

Cant you just convert the radians to degrees?

Cant you just convert the radians to degrees?

he said he wanted the function that returns an angle, "like when you press 2nd then sin on a calculator"

the only functions that *return* angles are the arcsin, arccos, and arctan functions -- the inverse trigonometric functions.

the standard functions (sin, cos, tan) require you to already know the angle, give it as an argument, then the functions return a ratio.

Well, you could try using the derived maths functions:

• [TEX]\sin^{-1}x = atan(\frac{x}{\sqrt{1-x^{2}}})[/TEX]
• [TEX]\cos^{-1}x = 2 * atan(1) - atan(\frac{x}{\sqrt{1-x^{2}}})[/TEX]

:)

>Well, you could try using the derived maths functions:
Why would he when he already have asin and acos?
Besides why did you complicated the formula for acos(x) which is simply:
$$acos(x) = \frac{\pi}{2}-asin(x)$$

>Why would he when he already have asin and acos?
That's what I meant with: