I am refactoring a graphic program that shows a drawing. The program uses its own transformation and the code is quite complicated. I'd like to refact the code with a transformation matrix instead.
The window and view coordinates are X to the right and Y to downwards.
The drawing in window uses the top left point as base point (0,0). The view is a screen rectangle area with base point (0,0) at the top left point too.
The view area can by any rectangle on the screen. It shows the drawing inside 80%x80% area leaving some margins around.
The drawing has a size of width x height. The program should show the drawing with the same scale ratio at both directions. The center of the drawing is mapping to the center of the view area. the drawing can be rotated in any angle between 0 ~ 360 degrees.
What is the general transformation matrix for this, given the following data:
- width and height of the drawing
- Rotation angle
- width and height of the view area
- Margins around the drawings