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

  • Thread starter Thread starter sarah22
  • Start date Start date
  • Tags Tags
    Rotating Shapes
Click For Summary
To rotate a shape in a 2D space around a center point, a specific formula is used. For a point (x, y) rotated by an angle θ around the origin (0,0), the new coordinates (x', y') can be calculated using the formulas: x' = x * cos(θ) - y * sin(θ) and y' = x * sin(θ) + y * cos(θ). In the example provided, rotating the line defined by points P1(-1,-1) and P2(1,1) by 45 degrees results in new coordinates P1(1,-1) and P2(-1,1), maintaining the center at C(0,0). The discussion highlights the importance of understanding these rotation formulas for effective 2D programming in C++.
sarah22
Messages
26
Reaction score
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
http://www.cgafaq.info/wiki/2D_Point_Rotation
 
Last edited by a moderator:
Ok thanks I got it.
 
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 14 ·
Replies
14
Views
2K