Drawing with the scheme:

enter image description here

It is necessary to rotate the image (red in the diagram) on the canvas (black) around the axis located in its center and cut the canvas so as to remove the empty areas appearing on the canvas. How to determine the size of the reduced canvas (blue)?

I know that if W >= H , then the equations

 WNew = H * W /(W * Sin(Fi) + H * Cos(Fi)) HNew = H * H /(W * Sin(Fi) + H * Cos(Fi)) 

And how to calculate WNew and HNew , if H > W ?

  • If your image is presented as a two-dimensional array - a matrix of colors, is it not easier to first flip, cut off the empty areas left after you turned over, determine the image size and calculate the required size, enter for example a coefficient that is responsible for centering as you need. And to reduce the image for example usual linear interpolation. - ParanoidPanda
  • I doubt your formulas ... See my answer. - Harry

2 answers 2

If the angle of rotation enter image description here then whatever the width and height

enter image description here

enter image description here

It is solved elementarily with the help of the rotation matrices , but I really do not want to paint all these actions.

The only thing - note that there may be situations when the new height, for example, begins to exceed the old one. So just a new image can stand out for the canvas. Well, here it is all quite simple - I think you will be able to find the intersection of two rectangles?

PS Let me doubt your formulas. At a minimum, they are non-linear, and with linear transformations this is nonsense ...

    My vision is the solution to this question, an extended answer regarding my comment in the header.

    Since you are working with an array of bytes (pixels), you will need to describe a point about which you need to and rotate the image, the point in the center. Next, you need to process the result - after rotation, you will have empty areas that need to be cut off. Follow your actions - you have an image and a canvas. Regarding the canvas, the image must be placed in the center and leave gaps, you must enter to calculate the coefficient, I will leave this iteration to you, your imagination is necessary here. After calculating the coefficient, you simply interpolate the image - reduce it. Well, it remains the most simple of the possible - you put in the center. Calculate the gaps relative to the upper, lower, left and right edges of the canvas.

    The task is actually interesting, I described my vision of the solution to this problem.