Professional Documents
Culture Documents
A Viewport is a rectangular region of the display device (hence in the device coordinate system) where we wish to display the contents of the window. 13 - 2
Window-To-Viewport Transformation
A Window-to-Viewport Transformation is thus a geometric transformation which maps a scene (or picture) from a real world window to a region of a display (viewport) and hence in The mapping is thus from the real world coordinate system to the device coordinate system. 13 - 3
Viewport Notation
Display Region (x MAX, y MAX)
(x V.MAX, y V.MAX)
(x MIN, y MIN)
(x V.MIN, y V.MIN)
13 - 5
Normalised device coordinates are the co-ordinates of the device expressed in normalised form
The normalised device co-ordinates are thus the coordinates used to express the display space
The co-ordinates are thus expressed in terms of their relative position on the display
Conventionally (0, 0) is at the bottom left hand corner of the display and (1, 1) is the top right corner of the display. Useful as they are device-independent
13 - 6
(0.8, 0.7)
(0, 0)
(0.2, 0.35)
13 - 7
Aspect Ratio
The Aspect Ratio of any rectangle is the ratio: (height of the rectangle) / (width of the rectangle) It is important for transformations from real world scenes to display with the same aspect ratio as any change in the aspect ratio may alter the appearance of the displayed object. Where the aspect ration is not maintained, shapes such as a circle may appear in the viewport as an ellipse, a square may appear as a rectangle etc.
13 - 8
Window-To-Viewport Transformation
Consider the case where we have successfully clipped some real world primitive against a window and we now wish to map the window and hence its contents to a region of a display device (viewport). Such a transformation requires us to map from real-world coordinates to screen coordinates. We must thus establish some 'transformation matrix' to perform this mapping.
13 - 9
Issues
Two very important issues must be addressed: 1 How do we ensure the same relative placement within the viewport as in the window?
13 - 10
Preserving Proportions in x
To preserve the same relative proportions in x: x W.DIST x V.DIST
x W.LENGTH
and hence
x V.LENGTH
xW
- x W.MIN
x W.MAX - x W.MIN
= x V.MAX -
xV
x V.MIN
x V.MIN
13 - 11
Preserving Proportions in y
To preserve the same relative proportions in y: y W.DIST y W.LENGTH and hence yW - y W.MIN yV y V.MIN y V.DIST y V.LENGTH
y W.MAX - y W.MIN
= y V.MAX -
y V.MIN
13 - 12
xV =
(x W -
x W.MIN) + x V.MIN
where Sx and Sy are scaling factors to scale from the window to viewport size and x V.MIN and y V.MIN are translation factors which take the scaled window coordinates to the lower left hand corner of the viewport
13 - 14
Is Sx = Sy ??
Note: IF Sx = Sy THEN the aspect ratio is maintained and thus the displayed objects will not be distorted. IF Sx <> Sy THEN the displayed objects will become distorted
13 - 15
An Example
Consider a viewport described by the rectangle whose lower left and upper right corner vertices are (256, 128) and (768, 640) respectively. A real world rectangular region (window) is described by the corner coordinates (0, 0) and (16, 32). Provide the appropriate window-to-viewport transformation. Express the 2 identified corner co-ordinates of the window and the centre of the window in absolute device co-ordinates
13 - 17
Another Example
A graph, representing income earned by a Salesman for each month in a year, is to be displayed onscreen.
Typical real world axes (plotting Months along the x-axis and Income along the y-axis) are such that: x W.MIN = 0 y W.MIN = 0 xW.MAX = 12 y W.MAX = 2000
A viewport occupies a portion of the screen described by: x V.MIN = 10 y V.MIN = 10 xV.MAX = 310 y V.MAX = 760 Provide a suitable window-to-viewport transformation.
13 - 18