79
Computer Graphics 2013 5. Geometry and Transform Hongxin Zhang State Key Lab of CAD&CG, Zhejiang University 2013-09-23 13923星期

Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013

5. Geometry and TransformHongxin Zhang

State Key Lab of CAD&CG, Zhejiang University

2013-09-2313年9月23⽇日星期⼀一

Page 2: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Today outline

• Triangle rasterization

• Basic vector algebra ~ geometry

• Antialiasing revisit

• Clipping

• Transforms (I)

13年9月23⽇日星期⼀一

Page 3: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Previous lesson

• Primitive attributes

• Rasterization and scan line algorithm

• line,

• general polygon

13年9月23⽇日星期⼀一

Page 4: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Seed Fill Algorithms• Assumes that at least one pixel interior to the

polygon is known

• It is a recursive algorithm

• Useful in interactive paint packages

Seed 4-connected 8 - connected

13年9月23⽇日星期⼀一

Page 5: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Polygon filling• Polygon representation

• By vertex By lattice

• Polygon filling:

• vertex representation vs lattice representation

13年9月23⽇日星期⼀一

Page 6: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Scan Line Method

• Proceeding from left to right the intersections are paired and intervening pixels are set to the specified intensity

• Algorithm

• Find the intersections of the scan line with all the edges in the polygon

• Sort the intersections by increasing X-coordinates

• Fill the pixels between pair of intersections

From top to down

http://www.cecs.csulb.edu/~pnguyen/cecs449/lectures/fillalgorithm.pdf

13年9月23⽇日星期⼀一

Page 7: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

• Intersections could be found using edge coherencethe X-intersection value xi+1 of the lower scan line can be

computed from the X-intersection value xi of the proceeding scan line as

• List of active edges could be maintained to increase efficiency

Efficiency Issues in Scan Line Method

13年9月23⽇日星期⼀一

Page 8: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Advantages of Scan Line method

• The algorithm is efficient

• Each pixel is visited only once

• Shading algorithms could be easily integrated with this method to obtain shaded area

• Efficiency could be further improved if polygons are convex,

• much better if they are only triangles

13年9月23⽇日星期⼀一

Page 9: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Convex?

A set C in S is said to be convex if, for all x and y in C and all t in the interval [0,1], the point

(1 − t ) x + t yis in C.

13年9月23⽇日星期⼀一

Page 10: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Convex polygon rasterization

One in and one out

13年9月23⽇日星期⼀一

Page 11: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Triangle Rasterization

13年9月23⽇日星期⼀一

Page 12: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Triangle Rasterization?

13年9月23⽇日星期⼀一

Page 13: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Triangle Rasterization

13年9月23⽇日星期⼀一

Page 14: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Compute Bounding Box

13年9月23⽇日星期⼀一

Page 15: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Point Inside Triangle Test

13年9月23⽇日星期⼀一

Page 16: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Line equation

13年9月23⽇日星期⼀一

Page 17: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

The Parallelogram Rule

13年9月23⽇日星期⼀一

Page 18: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Dot Product

13年9月23⽇日星期⼀一

Page 19: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Orthonormal Vectors

13年9月23⽇日星期⼀一

Page 20: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Coordinates and Vectors

13年9月23⽇日星期⼀一

Page 21: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Dot product between two vectors

13年9月23⽇日星期⼀一

Page 22: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Cross Product

13年9月23⽇日星期⼀一

Page 23: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Cross Product

13年9月23⽇日星期⼀一

Page 24: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

2~3D

13年9月23⽇日星期⼀一

Page 25: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Vector operations

13年9月23⽇日星期⼀一

Page 26: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Point operations

13年9月23⽇日星期⼀一

Page 27: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

illegal operations

13年9月23⽇日星期⼀一

Page 28: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Directed line

13年9月23⽇日星期⼀一

Page 29: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Perpendicular vector in 2D

13年9月23⽇日星期⼀一

Page 30: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Line equation

13年9月23⽇日星期⼀一

Page 31: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Normal to the line

13年9月23⽇日星期⼀一

Page 32: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Line equation

13年9月23⽇日星期⼀一

Page 33: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Line equation

13年9月23⽇日星期⼀一

Page 34: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Singularities

13年9月23⽇日星期⼀一

Page 35: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Handling singularity

13年9月23⽇日星期⼀一

Page 36: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Antialiasing

13年9月23⽇日星期⼀一

Page 37: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

• Aliasing is caused due to the discrete nature of the display device

• Rasterizing primitives is like sampling a continuous signal by a finite set of values (point sampling)

• Information is lost if the rate of sampling is not sufficient. This sampling error is called aliasing.

• Effects of aliasing are

– Jagged edges

– Incorrectly rendered fine details

– Small objects might miss

Aliasing

13年9月23⽇日星期⼀一

Page 38: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Aliasing(examples)

13年9月23⽇日星期⼀一

Page 39: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Aliasing(examples)

13年9月23⽇日星期⼀一

Page 40: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Aliasing(examples)

13年9月23⽇日星期⼀一

Page 41: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Antialiasing

• Application of techniques to reduce/eliminate aliasing artifacts

• Some of the methods are

– increasing sampling rate by increasing the resolution. Display memory requirements increases four times if the resolution is doubled

– averaging methods (post processing). Intensity of a pixel is set as the weighted average of its own intensity and the intensity of the surrounding pixels

– Area sampling, more popular

13年9月23⽇日星期⼀一

Page 42: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Antialiasing (postfiltering)How should one supersample?

13年9月23⽇日星期⼀一

Page 43: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

36

Area Sampling

• A scan converted primitive occupies finite area on the screen

• Intensity of the boundary pixels is adjusted depending on the percent of the pixel area covered by the primitive. This is called weighted area sampling

13年9月23⽇日星期⼀一

Page 44: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

• Methods to estimate percent of pixel covered by the primitive

–subdivide pixel into sub-pixels and determine how many sub-pixels are inside the boundary

–Incremental line algorithm can be extended, with area calculated as

x+0.5

Area Sampling

y+0.5

y-0.5

x-0.5 x

y

filled area

13年9月23⽇日星期⼀一

Page 45: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Clipping

13年9月23⽇日星期⼀一

Page 46: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

• Clipping of primitives is done usually before scan converting the primitives

• Reasons being–scan conversion needs to deal only with the clipped

version of the primitive, which might be much smaller than its unclipped version

–Primitives are usually defined in the real world, and their mapping from the real to the integer domain of the display might result in the overflowing of the integer values resulting in unnecessary artifacts

Clipping

13年9月23⽇日星期⼀一

Page 47: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Clipping

• Why Clipping?• How Clipping?

–Lines–Polygons

• Note: Content from chapter 4.–Lots of stuff about rendering systems and

mathematics in that chapter.

13年9月23⽇日星期⼀一

Page 48: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Definition

• Clipping – Removal of content that is not going to be displayed–Behind camera–Too close–Too far–Off sides of

the screen

13年9月23⽇日星期⼀一

Page 49: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

How would we clip?

• Points?• Lines?• Polygons?• Other objects?

13年9月23⽇日星期⼀一

Page 50: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

We’ll start in 2D

• Assume a 2D upright rectangle we are clipping against–Common in windowing systems–Points are trivial

• >= minx and <= maxx and >= miny and <= maxy

ab

c13年9月23⽇日星期⼀一

Page 51: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Line Segments

• What can happen when a line segment is clipped?

13年9月23⽇日星期⼀一

Page 52: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Cohen-Sutherland Line Clipping

• We’ll assign the ends of a line “outcodes”, 4 bit values that indicate if they are inside or outside the clip area.

1001 1000 1010

0001

0101 0110

0010

0100

0000

x < xminx > xmaxy < ymin

y > ymax

ymin

ymax

xmin xmax13年9月23⽇日星期⼀一

Page 53: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Outcode cases

• We’ll call the two endpoint outcodes o1 and o2. – If o1 = o2 = 0, both endpoints are inside.–else if (o1 & o2) != 0, both ends points are on the

same side, the edge is discarded.

1001 1000 1010

0001

0101 0110

0010

0100

0000

13年9月23⽇日星期⼀一

Page 54: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

More cases

• else if (o1 != 0) and (o2 = 0), (or vice versa), one end is inside, other is outside.–Clip and recompute one that’s outside until inside.–Clip edges with bits set…–May require two

clip computations 1001 1000 1010

0001

0101 0110

0010

0100

0000

13年9月23⽇日星期⼀一

Page 55: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Last case…

–else if (o1 & o2) = 0, end points are on different sides.• Clip and recompute. • May have some inside part or may not…• May require up to 4 clips!

1001 1000 1010

0001

0101 0110

0010

0100

0000

13年9月23⽇日星期⼀一

Page 56: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

48

• To do the clipping find the end point that lies outside

• Test the outcode to find the edge that is crossed and determine the corresponding intersection point

• Replace the outside end-point by intersection-point

• Repeat the above steps for the new line

ab

c

d

ef

g

h

i1001

0000

1010

0010

0100

Cohen-Sutherland Line-Clipping Algorithm

13年9月23⽇日星期⼀一

Page 57: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

49

Sutherland-Hodgeman Polygon-ClippingAlgorithm

• Polygons can be clipped against each edge of the window one edge at a time. Window/edge intersections, if any, are easy to find since the X or Y coordinates are already known.

• Vertices which are kept after clipping against one window edge are saved for clipping against the remaining edges.

13年9月23⽇日星期⼀一

Page 58: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

• Because polygon clipping does not depend on any other polygons, it is possible to arrange the clipping stages in a pipeline. the input polygon is clipped against one edge and any points that are kept are passed on as input to the next stage of the pipeline.

• This way four polygons can be at different stages of the clipping process simultaneously. This is often implemented in hardware.

Pipelined Polygon Clipping

ClipRight

ClipTop

ClipLeft

ClipBottom

13年9月23⽇日星期⼀一

Page 59: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

51

Sutherland-Hodgeman Polygon Clipping Algorithm

• Polygon clipping is similar to line clipping except we have to keep track of inside/outside relationships–Consider a polygon as a list of vertices–Note that clipping

can increase the number of vertices!

–Typically clip one edge at a time…

v1

v2

v3

v4

v5

13年9月23⽇日星期⼀一

Page 60: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

52

Sutherland-Hodgeman algorithm• Present the vertices in pairs

–(vn,v1), (v1, v2), (v2,v3), …, (vn-1,vn)–For each pair, what are the possibilities?–Consider v1, v2

Inside Outside Inside Outside Inside Outside Inside Outside

v1

v2 v1

v1

v1

v2

v2

v2

output v2 output i no output output i and v2

13年9月23⽇日星期⼀一

Page 61: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

53

Examplev5, v1

v1

v2

v3

v4

v5Inside Outside

v1

Inside Outside

Inside, InsideOutput v1

CurrentOutput

s

p

13年9月23⽇日星期⼀一

Page 62: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

54

v1,v2

v1

v2

v3

v4

v5Inside Outside

v1

v2

Inside Outside

Inside, InsideOutput v2

CurrentOutput

s

p

13年9月23⽇日星期⼀一

Page 63: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

55

v2, v3

v1

v2

v3

v4

v5Inside Outside

v1

v2

Inside Outside

Inside, OutsideOutput i1

CurrentOutput

s

p

i1

i1

13年9月23⽇日星期⼀一

Page 64: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

56

v3, v4

v1

v2

v3

v4

v5Inside Outside

Outside, OutsideNo output

s

p

v1

v2

Inside Outside

CurrentOutput

i1

13年9月23⽇日星期⼀一

Page 65: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

57

v4, v5 – last edge…

v1

v2

v3

v4

v5Inside Outside

Outside, InsideOutput i2, v5

s

p

v1

v2

Inside Outside

CurrentOutput

i1

i2 i2

v5

13年9月23⽇日星期⼀一

Page 66: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Transforms

13年9月23⽇日星期⼀一

Page 67: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Transformations

• Procedures to compute new positions of objects

• Used to modify objects or to transform (map) from one co-ordinate system to another co-ordinate system

As all objects are eventually represented using points, it is enough to know how to transform points.

13年9月23⽇日星期⼀一

Page 68: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Translation• Is a Rigid Body Transformation

• Translation vector (Tx, Ty, Tz) or shift vector

x => x+ Txy => y + Tyz => z + Tz

13年9月23⽇日星期⼀一

Page 69: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Translating an Object

(Tx, Ty)

x

y

13年9月23⽇日星期⼀一

Page 70: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Scaling

• Scale factor (Sx, Sy, Sz)

• Changing the size of an object

Sy = 1 Sx = 1 Sx = Sy

x => x * Sx

y => y * Sy

z => z * Sz

13年9月23⽇日星期⼀一

Page 71: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Scaling an Object

(x, y)

(x’, y’)

x

y

13年9月23⽇日星期⼀一

Page 72: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Scaling (contd.) Scaling is always with respect to the origin. The origin

does not move.

Scaling wrt a reference point can be achieved as a composite transformation

13年9月23⽇日星期⼀一

Page 73: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Scaling an Object

(x0,y0)

Question8 : How ?

13年9月23⽇日星期⼀一

Page 74: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Shearing• Produces shape distortions

• Shearing in x-direction

x => x + a* y

y => y

z => z

13年9月23⽇日星期⼀一

Page 75: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Rotation

x

y

α

θ

(x, y)

(x’, y’)

13年9月23⽇日星期⼀一

Page 76: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Rotation• Is a Rigid Body Transformation

x’ = r · cos(α+θ) = r cos α cos θ - r sin α sin θ = x cos θ - y sin θ

13年9月23⽇日星期⼀一

Page 77: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

Rotation (contd.)

• Rotation also is wrt to a reference -

• A Reference Line in 3D

• A Reference Point in 2D

• Define 2D rotation about arbitrary point

13年9月23⽇日星期⼀一

Page 78: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

x

y

φ

θ

(x, y)

(x’, y’)

(xr, yr)newx = x−xrnewy = y−yr

newxʹ′ = newx cosθ − newy sinθnewyʹ′ = newy cosθ + newx sinθ

xʹ′ = newxʹ′ + xr yʹ′ = newyʹ′ + yr

xʹ′ = xr+(x−xr)cosθ − (y−yr)sinθyʹ′ = yr+(y−yr)cosθ +(x−xr)sinθ

Rotate around (xr,yr)

13年9月23⽇日星期⼀一

Page 79: Computer Graphics 2013 5. Geometry and Transform · 2014-05-22 · State Key Lab of CAD&CG, ... end point that lies outside • Test the outcode to find the edge that is crossed and

Computer Graphics 2013, ZJU

General Linear Transformation

• Which of the following can be represented in this form?

•Translation

•Scaling

•Rotation

or

13年9月23⽇日星期⼀一