Transformations play a very important role in manipulating objects on screen. It should be noted that here the algorithms will be implemented in code and the built-in functions will not be used to give a good understanding of how the algorithms work.
Also note that all transformations are implemented in 2D.
There are three basic kinds of Transformations in Computer Graphics:
- Translation : Translation refers to moving an object to a different position on screen.
Formula: X = x + tx Y = y + ty where tx and ty are translation coordinates The OpenGL function is glTranslatef( tx, ty, tz );
- Rotation : Rotation refers to rotating a point.
Formula: X = xcosA - ysinA Y = xsinA + ycosA, A is the angle of rotation. The above formula will rotate the point around the origin. To rotate around a different point, the formula: X = cx + (x-cx)*cosA - (y-cy)*sinA, Y = cx + (x-cx)*sinA + (y-cy)*cosA, cx, cy is centre coordinates, A is the angle of rotation. The OpenGL function is glRotatef (A, x, y, z).
- Scaling : Scaling refers to zooming in and out an object in different scales across axes.
Formula: X = x*sx Y = y*sy, sx, sy being scaling factors. The OpenGL function is glScalef(float x, float y, float z)
Note: If combined transformations is to be applied, follow the order: translate, rotate, scale
This article is contributed by Suprotik Dey. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.