Sign in to follow this  

sine, cosine, and the GCC

This topic is 3311 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using simple functions to transform radians into degrees from the sin() cos() and tan() functions in <cmath>. When I ask for the value for COS(90) (my cos() function), I get 1.61554e-15. Now, I know this is very small, but it should be 0. Is this a rounding error, a granularity error (I'm using doubles), a problem with the accuracy of my PI value (3.14159265358979), or do I just need to create a special case for when cos angles reach 90 degrees?

Share this post


Link to post
Share on other sites
I'd love to, but I'm using the results to go into matrices for OpenGL, which uses degrees rather than radians.Still, if it's only precision errors, then I'll just have to keep an eye on it, and not worry too much. Thanks for the help.

Share this post


Link to post
Share on other sites
Quote:
I'd love to, but I'm using the results to go into matrices for OpenGL, which uses degrees rather than radians.
This doesn't quite make sense, given what you've posted.

The only parts of the OpenGL API that use degrees (that I'm aware of, at least) are the glRotate*() functions. Are you using one of these functions? And if so, how would (e.g.) cos() or sin() come into play anyway?

In other words, I'm not quite clear on why using OpenGL would force you to use degrees in the way you've shown.

Also, the rounding errors you've described are to be expected, and in this context at least can almost certainly be safely ignored.

Share this post


Link to post
Share on other sites
So if I was plugging degrees into a matrix that I intend to use with glLoadMatrix(), I would need the results in radians anyway? I was under the impression that degrees would be used throughout OpenGL, rather than just in the glRotateX() family of functions

Share this post


Link to post
Share on other sites
I think there are some confusion here. Either on our side for not understanding your application, of on your side for not understanding how angles are used in OpenGL.

The only place in OpenGL where you work with angles is in the parameters to glRotate. Note that; the parameters to glRotate. Once the matrix is created, there are no angles anymore; there is only a matrix. glLoadMatrix accepts a matrix and there are no angles in that matrix either. Whether you construct the matrix from radians or angles is completely irrelevant to the content of the matrix. A rotation of one quarter of a turn, let it be 90 degrees or pi/2 radians, is always a rotation of one quarter.

Share this post


Link to post
Share on other sites
Sorry, I meant that I was using degrees with cos() and sin() to generate the contents of the matrix. I wasn't actually plugging degree values directly into matrices, that was merely poor wording on my behalf, and I apologise for it.

Share this post


Link to post
Share on other sites
Are you a beginner programmer? A +-???E-15 instead of a 0 is an elementary property of double precision floating point numbers. In fact in a documentation of majority of programming languages is written: you can't expect the cos(PI/4) would exactly equal 0, a programmer who need cos(PI/4) to be exactly 0 should use 1 - cos(PI/4)^2 instead. (The reason behind this is a CPU sincos function. cos() is complementary to the sin().)

Share this post


Link to post
Share on other sites

This topic is 3311 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this