How do I rotate a 2D shape in C++?

In summary, a rotating shape in 2D C++ is a geometric figure that can be rotated around a fixed point using the <code>rotate()</code> function from the <code>graphics.h</code> library. Rotating shapes in 2D C++ has various purposes, including creating animations, designing games, and visualizing data. Multiple shapes can be rotated at once using a <code>for</code> loop, but there is a limitation in that the shape will rotate around its center point. To rotate a shape around a different point, you can use translation techniques.
  • #1
sarah22
26
0
I'm creating a C++ 2D program to practice my 2D skills. I'm almost done with everything but I'm stuck on this crap. Is there any formula on how to rotate a shape?

Example:

I have a line P1(-1,-1) P2(1,1)

If I rotate it by 45 degrees, I'll get a P1(1,-1) P2(-1,1). By the way, it should not leave its center which is C(0,0).
 
Technology news on Phys.org
  • #2
http://www.cgafaq.info/wiki/2D_Point_Rotation
 
Last edited by a moderator:
  • #3
Ok thanks I got it.
 

Related to How do I rotate a 2D shape in C++?

1. What is a rotating shape in 2D C++?

A rotating shape in 2D C++ is a geometric figure that can be rotated around a fixed point in a two-dimensional space. This rotation can be achieved by changing the angle of the shape's vertices relative to the fixed point.

2. How can I rotate a shape in 2D C++?

To rotate a shape in 2D C++, you can use the rotate() function from the graphics.h library. This function takes the coordinates of the shape's vertices and the angle of rotation as parameters, and then performs the rotation accordingly.

3. What is the purpose of rotating shapes in 2D C++?

Rotating shapes in 2D C++ can be used for various purposes, such as creating animations, designing games, or visualizing data. It can also be used in engineering and architecture for creating 3D models by rotating 2D shapes around different axes.

4. Can I rotate multiple shapes at once in 2D C++?

Yes, you can rotate multiple shapes at once in 2D C++ by using a for loop to iterate through each shape and applying the rotate() function to each one.

5. Are there any limitations to rotating shapes in 2D C++?

One limitation of rotating shapes in 2D C++ is that the shape will rotate around its center point, which may not always be desirable. To rotate a shape around a different point, you can first translate the shape's coordinates to the desired point, then perform the rotation, and finally translate the coordinates back to their original position.

Similar threads

  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Mechanical Engineering
Replies
2
Views
830
Replies
5
Views
1K
Replies
14
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
Replies
1
Views
640
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
4
Views
3K
Back
Top