You are on page 1of 18

Lecture Thirteen Window-to-Viewport Transformations

Definitions - Windows & Viewports


A Window is a rectangular region of the real world coordinate system that surrounds that portion of the image that we wish to have displayed.

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

Unique Identification of a Window


(x W.MAX, y W.MAX)
Example real-world windows include photographs, graphs, pictures, etc. Corner coordinates are expressed using Real-World values (x W.MIN, y W.MIN)
13 - 4

Some real world Window

Viewport Notation
Display Region (x MAX, y MAX)

Viewport within the Display Region

(x V.MAX, y V.MAX)

(x MIN, y MIN)

(x V.MIN, y V.MIN)
13 - 5

Normalised Device Co-ordinates

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

Normalised Device Co-ordinates


Display Region (1, 1) Viewport

(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?

2 Are we required to maintain the same relative proportions of objects?

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

Simplifying the Mappings (1)


For the x-coordinate we have:
x V.MAX - x V.MIN x W.MAX - x W.MIN For the y coordinate we have: yV = y V.MAX - y V.MIN y W.MAX - y W.MIN (y W y W.MIN) + y V.MIN
13 - 13

xV =

(x W -

x W.MIN) + x V.MIN

Simplifying the Mappings (2)


Each of these equations is of the form:
xV yV = = Sx (x W Sy (y W x W.MIN) + x V.MIN y W.MIN) + y 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

Special Effects - Zooming & Panning


Zooming is achieved by successively mapping different sized windows onto a fixed sized viewport. As the windows are made smaller, we zoom in on some part of the scene to view details that are not shown with larger sized windows. More overview is obtained by zooming out from a section of a scene with successively larger windows.
Panning is achieved by moving a fixed sized window across the various objects in a scene. Panning is thus characterised by movement across a scene.
13 - 16

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

You might also like