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

  • Thread starter Thread starter sarah22
  • Start date Start date
  • Tags Tags
    Rotating Shapes
AI Thread 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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top