Qt logical coordinates and physical coordinates

Personal Qt coordinate system conversion process of understanding

      QT coordinate transformation personal understanding mechanisms
      for a given drawing device, there are two coordinate systems when the drawing: physical coordinates, logical coordinate system. Coordinate system is an actual physical coordinate system, in the QT, the origin in the upper left corner of the drawing apparatus, which is a pixel length per unit length on the drawing device, the right X-axis growth, the growth of the Y-axis. Coordinate system and the logic is an abstract coordinate system whose origin unit length of no practical significance, the right X-axis growth, the growth of the Y-axis.
When the drawing image drawn on the logical coordinate system, and then through the window - viewport mapping, the mapping logic will convert the world coordinate system to a physical coordinate system. Further plotted on the coordinate system of the image logically mapped to the physical coordinate system.
       Note: In personal understanding, is to carry out the window - viewport mapping, and then convert the world. (But the document described is to be the world's conversion, then the window - viewport mapping, can not figure out if this is not the first through the window - viewport mapping abstract logical coordinate system specific, has converted its world What is the significance? the logical coordinate system to determine the origin of the concrete meaning and logic unit length coordinate system).
       Is first window (window) - viewport (the viewport) conversion:
       important to understand that: the window based on the logical coordinate system, based on the physical viewport coordinate system. The following two functions can be based on a logical window rectangle coordinate system, and based on a physical viewport rectangle coordinates.
QPainter :: setWindow void (int X, Y int, int width, int height) 
void QPainter :: setViewport (int X, Y int, int width, int height)
       Window - viewport is converted by two rectangles, map logical coordinates to the physical coordinates (it can be said to embody the logical coordinate system). Which is determined by way of physically moving coordinate system, drawing the logical coordinate system, such that the window rectangle viewport rectangle coincides this case moves through the logical coordinate system is obtained by stretching mapped on the physical coordinate system.
      Followed by conversion of the world. There are four ways to convert the world (currently I know):
(1) Translate () translation.
(2) scale () stretching, scaling.
(3) rotate () to rotate.
(4) shear () twist.
       Converting world is already embodied in the base coordinate system logic on its pan, stretching, scaling, rotation, distortion and other operations. Note that each of the world's conversions are carried out on the basis of the last conversion of the world. World conversion process is a state machine transition process. Therefore translation followed by a rotation, a translation and rotation followed result obtained is different.
       Through the above mapping, the image drawn on the logical coordinate system will be able to convert an image on a physical coordinate system.
NOTE: Window - viewport only to provide a conversion from the logical coordinate system to a physical coordinate system mapping manner, does not play a role in the cutout region, that is drawn outside the logical coordinate system image window rectangle will be mapped to on the physical coordinate system, and displayed.
       If no setWindow specified window tiling, the default setting is a rectangular window rectangle drawing device. This default setting also applies to the viewport rectangle (drawing equipment QWidget, QPixmap something like).

 

Example: logical coordinates (window)

. 1      QPainter Painter ( the this );
 2      // logical coordinates (-50, -50) is mapped to the viewport (0,0), the window size is (100,100) 
. 3      painter.setWindow (- 50 , - 50 , 100 , 100 );
 . 4      painter.setBrush (the Qt :: Green);
 . 5      // the drawRect pattern is drawn on the logical coordinates, just as the changing size of the viewport, logical coordinates may also change, to adaptive form effect; 
. 6      painter.drawRect ( 0 , 0 , 20 is , 20 is );
 . 7      // form default size (400, 300), the logical window adaptive viewport mapping coordinates (200, 150), the size of the rectangle (80, 60 );

Example: physical coordinates (viewport)

. 1      QPainter Painter ( the this );
 2      int Side = Qmin (width (), height ());
 . 3      int X = (width () / 2 );
 . 4      int Y = (height () / 2 );
 . 5      // will viewport (drawing device physical coordinates) is set to half of the original form, the starting coordinates of the center of the original form, take the original size of the form of the minimum width and height; 
. 6      painter.setViewport (X, Y, Side, Side );
 . 7      painter.setWindow ( 0 , 0 , 100 , 100 );
 . 8      painter.setBrush (the Qt :: Green);
 . 9      painter.drawRect ( 0 , 0 , 20 is,200);

 

 

Guess you like

Origin www.cnblogs.com/mtn007/p/11909435.html