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?

Recommended Answers

All 13 Replies

Hard time converting radians to angles?

commented: lol +12

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:

degrees = radians * 180/pi

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)


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


.

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()"

follow the links i provided above and you'll see the prototypes.

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]

:)

Edit:: Sorry jephthah, I didn't read your post carefully :(

>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:
[tex]acos(x) = \frac{\pi}{2}-asin(x)[/tex]

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

Edit:: Sorry jephthah, I didn't read your post carefully :(

Besides that, the answer I gave wasn't wrong, only a bit sluggish if there are already functions like asin and acos in the standard function library.
So, there's no other possibility left then completely agree with you :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.