2 d viewing computer graphics

20
2D Viewing Arambam Neelima Dept of CSE, NIT Nagaland

Transcript of 2 d viewing computer graphics

Page 1: 2 d viewing computer graphics

2D Viewing

Arambam Neelima

Dept of CSE, NIT Nagaland

Page 2: 2 d viewing computer graphics
Page 3: 2 d viewing computer graphics

Clipping

• The technique for not showing the part of thepicture in which one is not interested is calledas clipping.

• A graphics package allows a user to specifywhich part of a defined picture is to bedisplayed and where that part is to be placedon the display device

Page 4: 2 d viewing computer graphics

• A view for a 2D picture is selected by specifying aregion of the xy plane that contains the totalpicture or any part of it

• select parts of Picture areas are then mappedonto specified areas of the device coordinates

• 2D viewing transformations from world to devicecoordinates involve translation, rotation, andscaling operations, as well as procedures fordeleting those parts of the picture that areoutside the limits of a selected scene area

Page 5: 2 d viewing computer graphics

Co-ordinate system

• World Co-ordinate System: Right handedcartesian co-ordinate system in which wedescribe the co-ordinates of the picture to bedisplayed.

• Device Co-ordinate System: Co-ordinatesystem corresponding to the device in whichwe want to display.

Page 6: 2 d viewing computer graphics

Viewing transformation system

• The process of mapping a part of the worldco-ordinate scene to device co-ordinatesystem is known as viewing transformation.

• A world co-ordinate area selected for displayis called as a window and an area on displaydevice to which a window is mapped is calledas a view point.

• Window defines ‘What’ to be viewed and theviewport defines ‘Where’ it is to be displayed

Page 7: 2 d viewing computer graphics

Window

Object in World Co-ordinate system

Object in Device co-ordinate system

Page 8: 2 d viewing computer graphics

• Case I: If we change the position of the windowkeeping the viewport location constant then thedifferent part of the object is displayed at thesame position on the display device

• Case II: If we change the location of the viewportbut keep the window constant then the samepart of the object is drawn at different place.

• Changing the size of viewports, we can change the size and proportions of displayed objects; zoom in and zoom out effects

Page 9: 2 d viewing computer graphics

Normalization

Normalization: Specify coordinate values between 0 and1

• normalization and window to viewporttransformations can be combined into one operation.

• In this case, the viewport coordinates in the range from0 to 1 so that the viewport is positioned within a unitsquare

• Unit square containing the viewport is mapped to theoutputdisplay device

• normalization and clipping routines are applied beforethe viewport transformation

Page 10: 2 d viewing computer graphics

• Object descriptions are transferred to this normalized spaceusing a transformation that maintains the same relativeplacement of a point in the viewport as it had in the clippingwindow

• Position (xw, yw) in the clipping window is mapped to position(xv, yv) in the associated viewport

Page 11: 2 d viewing computer graphics

• To transform the world-coordinate point into the same relative position within the viewport, we require,

• Solving these equations for xv and yv

where

Page 12: 2 d viewing computer graphics

• Window to viewport Window-to-viewport transformation Relative placement of object descriptions is maintained Relative proportions of objects, on the other hand, are maintained only if the aspect ratio of viewport is same as that of clipping window i.e. sx = sy Else, world objects will be stretched or contracted in either the x or y directions (or both) when displayed on the output device

• Clipping window to normalized viewport clipping routines can be applied using either the clipping window boundaries or the viewport boundaries normalized coordinates are transformed into device coordinates the unit square can be mapped onto the output device by translation and scaling

Page 13: 2 d viewing computer graphics

Point Clipping

• Given a clipping rectangle in standard position, we save a two-dimensional point P = (x, y) for display if

• If any of these inequalities is not satisfied, the point is clipped i.e. not saved for display

Page 14: 2 d viewing computer graphics

Line Clipping

• A line-clipping algorithm processes each linein a scene to determine whether the entireline or any part of it is to be saved for display

Page 15: 2 d viewing computer graphics

• Line Clipping

• Need to compute intersection points of lines with clipping window

• minimize intersection calculation for better algorithm

• Test whether a line segment is completely inside the clipping window or completely outside

• Completely inside – easy; both points are inside – P1P2

• Completely outside – difficult; both points outside?? – P3P4

• If not possible –Test whether any part of a line crosses the window interior

Page 16: 2 d viewing computer graphics

COHEN SUTHERLAND LINE CLIPPING

One of the earliest algorithms for fast line clipping

• Processing time is reduced by performing more tests before proceeding to the intersection calculations

• Every line endpoint in a picture is assigned a four-bit binary value – region code

• Each bit position is used to indicate whether the point is inside or outside one of the clipping-window boundaries

Bit 4 Bit 3 Bit 2 Bit 1

Bottom Right LeftTop

Bit 1 is set to 1 when point lies to left of the windowBit 2 is set to 1 when point lies to right of the windowBit 3 is set to 1 when point lies below/bottom of windowBit 4 is set to 1 when point lies above the window

Page 17: 2 d viewing computer graphics

• Bit values in a region code determined by comparing the

• coordinate values (x, y) endpoints to the clipping boundaries

• Bit 1 is set to 1 if x < xwmin

• Bit 2 is set to 1 if x > xwmax• Bit 3 is set to 1 if y < ywmin• Bit 4 is set to 1 if y > ywmax

• Calculate differences between endpoint coordinates and clipping boundaries.

• Use the resultant sign bit of each difference calculation to set

• the corresponding value in the region code.

Page 18: 2 d viewing computer graphics

• For any given line,• If both endpoints have region code 0000 – completely

inside• If both endpoints has a region-code value of 1 in at

least one same bit position – completely outside the clipping rectangle, and we eliminate that line segment

• Lines that cannot be identified as completely inside or completely outside are checked for intersections

• As each clipping-window edge is processed, a section of the line is clipped, and remaining part of the line is checked against the other window borders

• Eliminate sections until either the line is totally clipped or the remaining part of the line is inside the clipping window.

Page 19: 2 d viewing computer graphics

• To determine a boundary intersections, use the slope intercept form of the line equation

• For a line with endpoint coordinates (x0, y0) and (xend, yend),

• For intersection point with a vertical clipping border line, ycoordinate is obtained with the calculation

where the x value is set to either xwmin or xwmax• Similarly, for intersection with a horizontal border, the

xcoordinate is calculated as

with y set either to ywmin or to ywmax

Page 20: 2 d viewing computer graphics

• Use Cohen Sutherland algorithm to clip the line P(70,20) and Q(100,10) against a window lower left hand corner (50,10) and upper right hand corner (80,40).

(70,20) and (80, 16.667)