20
Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

Embed Size (px)

Citation preview

Page 1: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

Computer Graphics- SCC 342

Chapter 4: Graphics Output Primitives

Dr. Doaa Hegazy

Page 2: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

2D Graphics Primitives• Graphics drawing is based on basic geometric

structures called graphics primitives– Points– Lines– Circles– Conic Sections

Page 3: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.1 Coordinate Reference Frames

• To describe a picture, first decide upon a convenient Cartesian coordinate system, called the world-coordinate reference frame

• WCR can be 2D or 3D• Objects in pictures described by:– positions in world coordinates– Color– coordinate extents = the minimum and maximum

x, y, and z values for each object

Page 4: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.1 Coordinate Reference Frames

Screen Coordinates• Locations on a video monitor are referenced in

integer screen coordinates, which correspond to the pixel positions in the frame buffer

• Pixel coordinate values give the scan line number (the y value) and the column number (the x value along a scan line)

• Scan-line algorithms for the graphics primitives use the defining coordinate descriptions to determine the locations of pixels that are to be displayed

Page 5: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.1 Coordinate Reference Frames

Screen Coordinates• For the present, we assume that each integer

screen position references the center of a pixel area

Page 6: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.1 Coordinate Reference Frames

Absolute and Relative Coordinate Specifications• Absolute coordinate values: the values

specified are the actual positions within the coordinate system in use

• Relative coordinates: we can specify a coordinate position as an offset from the last position that was referenced (called the current position)

Page 7: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.6 File Area Primitives

• Another useful component beside geometric objects is describing an area with filled color

• Referred to as fill area or filled area• Most graphics routins require the fill area to specified

as polygon- their boundries are described by linear equations.- most surface can be approximated by polygons (called surface tessellation)

Page 8: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.7 Polygon Fill Area

• Polygons: plane figure specified by three or more vertices and connected by edges

• Has all vertices within plane- no edge crossing• Polygon classification:

- Convex: interior angle = or less than 180 degrees- Concave: interior angle greater than 180 degrees

• Implementations for filling algorithms are complicated for concave polygons

concaveconvex

Page 9: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.7 Polygon Fill Area

Identifying concave polygons- extension of some edges will intersect other edges- take a look at the polygon vertex positions relative to the extension line of any edge: some vertices are on one side and some are on the other

9

Page 10: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.7 Polygon Fill Area

- Split concave polygons into a set of convex polygons

- Using edge vectors and edge cross products

- Use vertex position relative to edge extension line.

10

Splitting concave polygons

Page 11: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.7 Polygon Fill Area

11

Splitting concave polygons• Assume all polygons in xy plane• Ek = Vk+1 – Vk

• Calculate cross product of successive edge vectors- if at least z component of one vector is negative, then concave polygon.- no successive vertices are collinear.

• Split along the line of the first edge vector in the cross product pair.

Page 12: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.7 Polygon Fill AreaSplitting concave polygons

12

Page 13: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.7 Polygon Fill AreaSplitting concave polygons

13

Page 14: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.7 Polygon Fill AreaSplitting concave polygons• Another method is a rotational method

14

Page 15: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.7 Polygon Fill Area

15

Splitting convex polygons into triangle (tessellation)- define any sequence of three consecutive vertices to a triangle.- delete middle vertex from the original list- continue forming triangle- stop when only three vertices are remaining.

Page 16: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.7 Polygon Fill Area

Inside-Outside test • Also called odd-even test

16

P

Q

Page 17: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.7 Polygon Fill AreaWinding-Number test• Count counterclockwise encirclements of

point

17

P

Q

Page 18: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.7 Polygon Fill Area

Polygon tables• objects in a scene are described as sets of

polygon surface facets• Object description includes:

- Coordinate information (geometry for the polygon facets)

- Surface parameters(color, transparency, and light-reflection properties)

• Object information are organized in tables.

18

Page 19: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.7 Polygon Fill AreaPolygon tables

19

Page 20: Computer Graphics- SCC 342 Chapter 4: Graphics Output Primitives Dr. Doaa Hegazy

4.7 Polygon Fill Area

Polygon tables• Important for check for consistency and

completeness:1. each pixel is an end point for at least two edges.2. every edge is part of at least one polygon3. every polygon is closed4. each polygon has at least one shared edge

20