# Polygon Rotation

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

• # Polygon Rotation

Hello

I have a simple question about polygon rotation, that I couldn't find the answer in reference manual.
I want to know what is the origin point of rotation in function GUI_RotatePolygon? I mean this function rotates the polygon around to which point?
Can we change the origin point of rotation?

Thank you

The post was edited 1 time, last by Karim ().

• Hello,

the coordinates of polygon are considered related to the origin point when drawing the polygon.

When rotating the polygon the origin point is the pivot point of the polygon that can be inside and outside the polygon depending on its coordinates.

Аfter rotation is done you can draw rotated polygon related to the new origin point.

### C Source Code

1. #include "DIALOG.h"
2. // Source polygon
3. // The coords of the polygon set that the origin and pivot point is inside the polygon
4. GUI_POINT pSource1[] = { {-10, 10}, {-10, -90}, {0, -100}, {10, -90}, {10, 10} };
5. // The coords of the polygon set that the origin and pivot point is outside the polygon
6. GUI_POINT pSource2[] = { {-10, -20}, {-10, -90}, {0, -100}, {10, -90}, {10, -20} };
7. // Rotated polygon
8. GUI_POINT pDest1[5], pDest2[5];
10. GUI_Init();
11. // Origin point is inside the polygon
12. GUI_DispStringHCenterAt("Origin point is inside the polygon", 160, 10);
13. // Draw the origin point (100, 120)
14. GUI_DrawPoint(100, 120);
15. // Draw the source polygon with the origin point
16. GUI_DrawPolygon(pSource1, GUI_COUNTOF(pSource1), 100, 120);
17. // Rotate the source polygon
18. GUI_RotatePolygon(pDest1, pSource1, GUI_COUNTOF(pSource1), 45 * 0.01745329);
19. GUI_SetColor(GUI_RED);
20. // Draw the rotated polygon with the same origin point
21. GUI_DrawPolygon(pDest1, GUI_COUNTOF(pDest1), 100, 120);
22. GUI_SetColor(GUI_GREEN);
23. // Draw the new origin point (300, 120)
24. GUI_DrawPoint(300, 120);
25. // Draw the rotated polygon with the new origin point
26. GUI_DrawPolygon(pDest1, GUI_COUNTOF(pDest1), 300, 120);
27. // Origin point is outside the polygon
28. GUI_SetColor(GUI_WHITE);
29. GUI_DispStringHCenterAt("Origin point is outside the polygon", 160, 170);
30. // Draw the origin point (100, 280)
31. GUI_DrawPoint(100, 280);
32. // Draw the source polygon with the origin point
33. GUI_DrawPolygon(pSource2, GUI_COUNTOF(pSource2), 100, 280);
34. // Rotate the source polygon
35. GUI_RotatePolygon(pDest2, pSource2, GUI_COUNTOF(pSource2), 45 * 0.01745329);
36. GUI_SetColor(GUI_RED);
37. // Draw the rotated polygon with the same origin point
38. GUI_DrawPolygon(pDest2, GUI_COUNTOF(pDest2), 100, 280);
39. GUI_SetColor(GUI_GREEN);
40. // Draw the new origin point (300, 280)
41. GUI_DrawPoint(300, 280);
42. // Draw the rotated polygon with the new origin point
43. GUI_DrawPolygon(pDest2, GUI_COUNTOF(pDest2), 300, 280);
44. while (1);
45. }
Display All

Alex.
• Thank you Alex.
It was a very good sample code.
As I understood we can set the origin point by using GUI_DrawPoint() function. And after that the rotation will be done according to that point.
Did I understand correctly?
• Yes, we could say that, I suppose.

I would say, the term of the origin point is applicable when drawing the polygon.

Rotation of the polygon is doing in relative coordinates. When we are drawing rotated polygon we set the origin point again for drawing it in right place.

Alex.
• Thank you Alex. I think I got.
The pivot point is set by how we define the polygon points.