Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 U08181 Computer Graphics Clipping Transformations –Transformations and matrices –Homogeneous matrices –Transformations in SVG.

Similar presentations


Presentation on theme: "1 U08181 Computer Graphics Clipping Transformations –Transformations and matrices –Homogeneous matrices –Transformations in SVG."— Presentation transcript:

1 1 U08181 Computer Graphics Clipping Transformations –Transformations and matrices –Homogeneous matrices –Transformations in SVG

2 2 M08734 Introduction to Computer Graphics Clipping finding the parts of a shape that lie within (outside) a ‘clipping region’ useful for ‘window’ display

3 3 Possible intersections

4 4 Example: Cohen-Sutherland algorithm (xMin, yMin) (xMax, yMax) (x1, y1) Clip line to rectangle (x2, y2)

5 5 Clipping: value of set {right, top} {left, top} {right, bottom} {left, bottom} {bottom} {right} {left} {top} { }

6 6 Accepted and rejected lines If Encode(x1, y1)  Encode(x2, y2) = { } then line (x1, y1) to (x2, y2) lies entirely within clipping region If Encode(x1, x2)  Encode(x2, y2)  {} then line lies entirely outside region

7 7 Use of sets (Pascal syntax) S  T is written S + T (union) S  T is written S * T (intersection) x  S is written x IN S (membership)

8 8 Function Encode TYPE Edge = (left, right, bottom, top); EdgeSet = SET OF Edge; FUNCTION Encode (x, y: REAL): EdgeSet; VAR edges: EdgeSet; BEGIN edges := {}; IF x < xMin THEN edges := edges + {left} ELSIF x > xMax THEN edges := edges + {right} END; IF y < yMin THEN edges := edges + {bottom} ELSIF y > yMax THEN edges := edges + {top} END; RETURN edges END Encode;

9 9 Clipping PROCEDURE Clip (x1, y1, x2, y2, xMin, yMin, xMax, yMax: REAL); TYPE Edge = (left, right, bottom, top); EdgeSet = SET OF Edge; VAR p1Code, p2Code, code: EdgeSet; x, y: REAL; BEGIN p1Code := Encode(x1, y1); p2Code := Encode(x2, y2); WHILE (p1Code + p2Code # { }) & (p1Code * p2Code = { }) DO code := p1Code; IF code = { } THEN code := p2Code END; (* clip according to the set of encoded edges *) IF code = p1Code THEN x1 := x; y1 := y; p1Code := Encode(x1, y1) ELSE x2 := x; y2 := y; p2Code := Encode(x2, y2) END; (* (p1Code + p2Code = { }) OR (p1Code * p2Code # { }) *)

10 10 Do the clipping IF left IN code THEN x := xMin; y := y1 + (y2 - y1) * (xMin - x1) / (x2 - x1) ELSIF right IN code THEN x := xMax; y := y1 + (y2 - y1) * (xMax - x1) / (x2 - x1) END; IF bottom IN code THEN y:= yMin; x := x1 + (x2 - x1) * (yMin - y1) / (y2 - y1) ELSIF top IN code THEN y := yMax; x := x := x1 + (x2 - x1) * (yMax - y1) / (y2 - y1) END;

11 11 Draw the line (or not) (* (p1Code + p2Code = { }) OR (p1Code * p2Code # { }) *) IF p1Code + p2Code = { } THEN Line(ROUND(x1), ROUND(y1), ROUND(x2), ROUND(y2)) END

12 12 Transformations Translation Rotation Scaling

13 13 Translation Translation by tx and ty: x´ = x + tx y´ = y + ty

14 14 Rotation by angle  about (0, 0): x´ = x cos  – y sin  y´ = x sin  + y cos 

15 15 Scaling Scaling about (0, 0) by S x and S y : x´ = xS x y´ = yS y Note: negative S gives reflection

16 16 Matrices Represent point (x, y) by column vector:

17 17 Translation is vector addition

18 18 Rotation is matrix multiplication

19 19 Scaling is matrix multiplication

20 20 Homogeneous matrices It would be convenient if all transformations could be represented as matrix multiplication (cf translation) Solution: homogeneous matrices

21 21 Translation is matrix multiplication

22 22 Rotation is matrix multiplication

23 23 Scaling is matrix multiplication

24 24 Composition To rotate by  about a point (tx, ty) translate to origin rotate by  translate back Note order of matrix multiplications

25 25 Rotation by  about (tx, ty)

26 26 References


Download ppt "1 U08181 Computer Graphics Clipping Transformations –Transformations and matrices –Homogeneous matrices –Transformations in SVG."

Similar presentations


Ads by Google