Aug-25-2021, 03:47 PM
(This post was last modified: Aug-25-2021, 03:47 PM by deanhystad.)
I spent too much effort solving the wrong problem. The problem is not rotating a rectangle, the problem is rotating an image of a sail. When you first tried this you had a white rectangle rotating about it's center inside a black rectangle.
To solve the problem of the white rectangle rotating about it's center, the easy solution is make the image 4 times larger and place the sail (rectangle) so the mast is at the center of the image. That way when you rotate the image the sail will rotate about the mast. There is no need to calculate how a rectangle should move as it rotates about a point if there is no rectangle.
The second problem is the black rectangle. The solution here is to make the background of the image transparent so the only thing blitted to the screen is the sail part. Here's a tutorial about that:
https://riptutorial.com/pygame/example/2...ansparency
Frustratingly pygame measures angles in degrees and python.math measures them in radians. That would be one reason why your results were off. 90 degrees is PI/2 radians (1.57)
To solve the problem of the white rectangle rotating about it's center, the easy solution is make the image 4 times larger and place the sail (rectangle) so the mast is at the center of the image. That way when you rotate the image the sail will rotate about the mast. There is no need to calculate how a rectangle should move as it rotates about a point if there is no rectangle.
The second problem is the black rectangle. The solution here is to make the background of the image transparent so the only thing blitted to the screen is the sail part. Here's a tutorial about that:
https://riptutorial.com/pygame/example/2...ansparency
Frustratingly pygame measures angles in degrees and python.math measures them in radians. That would be one reason why your results were off. 90 degrees is PI/2 radians (1.57)