# Point rotation around point, accuracy question

I study OpenGL ES 2.0. But I think it's more a C++ question rather then an OpenGL one.

I am stuck with the following rotation question: It is known, that rotation transformation can be applied using these equations (for simplicity suppose we rotating around (0, 0)):

x'=x*cos(theta)-y*sin(theta)
y'=x*sin(theta)+y*cos(theta)


But it seems that when I perform this rotation operation several times, the accuracy problem occures. I guess that the core of this problem is in uncertain results of cos() function and floating point limitations. As a result I see that my rotating object is getting smaller and smaller and smaller. By the way I am using C++.

1.) What do you think: Is this issue really connected to the accuracy problem?

2.) If so, how can I handle this?

Thanks.

This type of accumulated error is usually dealt with by tracking the original point(s) (say, the vertices of a mesh), and their transformation (say, as a matrix or quaternion and scale/translation vectors) separately.

When you transform the object, you don't modify the original points. You just update the transformation data. Then a new set of output points can be generated on demand from the originals and the updated transformation.

Doing it this way lets you police the transformation data for errors. If you maintain the invariant that the transformation data is error-free to within your numerical precision, then any output points you generate will remain accurate within similar bounds.

You can do this in two ways:

1. Generate the transformation from scratch whenever you need it, from more reliable source data (like an angle variable).

2. Update the transformation incrementally, and error-correct it as you go:

A common example is working with a rotation matrix. A matrix that represents a rotation with no scaling/shearing is necessarily orthonormal (each row or column of the matrix is a unit vector, perpendicular to each other row or column, respectively). So, you can correct rounding errors that creep into the matrix by orthonormalizing it after making any change. (That is, take one row, scale it to unit length. Take the next row, subtract its projection onto rows considered so far, scale it to unit length. Repeat until you run out of rows)