Presentation is loading. Please wait.

Presentation is loading. Please wait.

Polygons.

Similar presentations


Presentation on theme: "Polygons."— Presentation transcript:

1 Polygons

2 Polygons

3 Triangle Meshes

4 Polygon Tables Vertex Table Edge Table Surface Table v1: x1, y1, z1
E1: v1, v2 E2: v2, v3 E3: x3, v1 E4: v3, v4 E5: v4, v5 E5: v5, v1 Surface Table S1: E1, E2, E3 S2: E3, E4, E5, E6

5 Front and Back Faces Any point (x, y, z) is: on the plane:
A.x + B.y + C.z + D = 0 behind the plane: A.x + B.y + C.z + D < 0 in front of the plane: A.x + B.y + C.z + D > 0 y in front of (outside) the plane x front face behind (inside) the plane z

6 Front and Back Faces A.x + B.y + C.z + D = 0 N = (v2-v1) x (v3-v1)
N.P = -D y Normal vector N=(A, B, C) v3 v2 x v1 z

7 all interior angles are
Polygons convex all interior angles are <1800 concave at least one angle is >1800

8 Identifying Concave Polygons
Method 1 if some vertices are on one side and some on the other side of an extension line, then concave v4 E3 E5 v3 E2 v1 v2 E1

9 Splitting Concave Polygons
Rotational Method Shift polygon so that each vertex vk in turn is at the coordinate origin Rotate polygon about the origin in clockwise direction so that next vertex vk+1 is on the x axis If vk+1 is below the x-axis, polygon is concave Split polygon along x-axis y v1 v2 v3 v4 v5 x

10 Splitting Concave Polygons
Rotational Method Shift polygon so that each vertex vk in turn is at the coordinate origin Rotate polygon about the origin in clockwise direction so that next vertex vk+1 is on the x axis If vk+1 is below the x-axis, polygon is concave Split polygon along x-axis v1 v2 v3 v4 v5 y x

11 Identifying Concave Polygons
Method 2 if cross product of adjacent vector pairs is <0, then concave v4 E3 E5 v3 E2 v1 v2 E1

12 Splitting Concave Polygons
Vector Method Find the cross products of edge vectors (Ek x Ek+1) If z component is negative then split polygon along the line of the first edge vector in the cross product pair Then find the intersection of the line with other edges of the polygon E4 v5 v4 E3 E5 v3 E2 v1 v2 E1

13 Splitting Convex Polygons into Triangles

14 Polygon Filling: Inside-Outside Test
Odd-Even Test Draw a line from any point P to a point outside the closed polyline If the number of line-segment crossings is: odd => P is an interior point even => P is an exterior point

15 Polygon Filling: Scan-Line Algorithm
Find intersection of polygon boundaries with screen scan lines (solving the pair of simultaneous linear equations where scanline is y, which is a constant) Apply fill-color to scan line sections that lie within the fill region (use odd-even rule)

16 Polygon Filling: Scan-Line Algorithm
Monotonically increasing/decreasing

17 Polygon Filling: Scan-Line Algorithm
Incremental calculation of intersection points yk+1 – yk =1 m = 1/ (xk+1 – xk ) xk+1 = xk + 1/m (xk+1, yk+1) yk+1 yk (xk, yk) xk xk+1

18 Polygon Filling: Boundary-Fill Algorithm
4-connected 8-connected

19 Polygon Filling: Boundary-Fill Algorithm
void boundaryFill4 (int x, int y, int fillColor, int borderColor) { int interiorColor; /* Set current color to fillColor, then perform following oprations. */ getPixel (x, y, interiorColor); if ((interiorColor != borderColor) && (interiorColor != fillColor)) setPixel (x, y); // Set pixel color to fillColor boundaryFill4 (x + 1, y , fillColor, borderColor); boundaryFill4 (x - 1, y , fillColor, borderColor); boundaryFill4 (x , y + 1, fillColor, borderColor); boundaryFill4 (x , y - 1, fillColor, borderColor) }

20 Polygon Filling: Boundary-Fill Algorithm
void boundaryFill4 (int x, int y, int fillColor, int borderColor) { int interiorColor; /* Set current color to fillColor, then perform following oprations. */ getPixel (x, y, interiorColor); if ((interiorColor != borderColor) && (interiorColor != fillColor)) setPixel (x, y); // Set pixel color to fillColor boundaryFill4 (x + 1, y , fillColor, borderColor); boundaryFill4 (x - 1, y , fillColor, borderColor); boundaryFill4 (x , y + 1, fillColor, borderColor); boundaryFill4 (x , y - 1, fillColor, borderColor) }

21 Polygon Filling: Boundary-Fill Algorithm
void boundaryFill4 (int x, int y, int fillColor, int borderColor) { int interiorColor; /* Set current color to fillColor, then perform following oprations. */ getPixel (x, y, interiorColor); if ((interiorColor != borderColor) && (interiorColor != fillColor)) setPixel (x, y); // Set pixel color to fillColor boundaryFill4 (x + 1, y , fillColor, borderColor); boundaryFill4 (x - 1, y , fillColor, borderColor); boundaryFill4 (x , y + 1, fillColor, borderColor); boundaryFill4 (x , y - 1, fillColor, borderColor) }

22 Polygon Filling: Boundary-Fill Algorithm
2 2 1 1

23 Polygon Filling: Boundary-Fill Algorithm
3 3 1 1

24 Polygon Filling: Boundary-Fill Algorithm
5 6 6 5 4 1 4 1

25 Polygon Filling: Boundary-Fill Algorithm
7 7 5 4 1 5 4 1

26 Polygon Filling: Boundary-Fill Algorithm
5 5 4 1 4 1

27 Polygon Filling: Boundary-Fill Algorithm
8 8 4 1 4 1

28 Polygon Filling: Boundary-Fill Algorithm
4 1 4 1

29 Polygon Filling: Boundary-Fill Algorithm
9 1 9 1

30 Polygon Filling: Boundary-Fill Algorithm
10 1 10 1

31 Polygon Filling: Boundary-Fill Algorithm
11 1 1 11

32 Polygon Filling: Boundary-Fill Algorithm
12 1 1 12

33 Polygon Filling: Boundary-Fill Algorithm
1 1

34 Polygon Filling: Flood-Fill Algorithm
void floodFill4 (int x, int y, int fillColor, int interiorColor) { int color; /* Set current color to fillColor, then perform following operations. */ getPixel (x, y, color); if (color = interiorColor) { setPixel (x, y); // Set pixel color to fillColor floodFill4 (x + 1, y, fillColor, interiorColor); floodFill4 (x - 1, y, fillColor, interiorColor); floodFill4 (x, y + 1, fillColor, interiorColor); floodFill4 (x, y - 1, fillColor, interiorColor) }

35 OpenGL Polygon Functions glRect*(x1, y1, x2, y2); Ex:
i (integer) s (short) f (float) d (double) v (vector) Ex: glRecti(50, 250, 200, 100); int v1[ ]={50, 250}; int v2[ ]={200, 100}; glRectiv(v1, v2); (50,250) (200,100)

36 OpenGL Ex: GL_POLYGON GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN
glBegin (GL_POLYGON); glVertex2iv(p1); glVertex2iv(p2); glVertex2iv(p3); glVertex2iv(p4); glVertex2iv(p5); glVertex2iv(p6); glEnd(); p6 p5 p1 p4 p2 p3 GL_POLYGON GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN

37 OpenGL Ex: GL_QUADS GL_QUAD_STRIP glBegin (GL_QUADS); glVertex2iv(p1);
glEnd(); p8 p1 p4 p5 p7 p6 p3 p2 GL_QUADS GL_QUAD_STRIP


Download ppt "Polygons."

Similar presentations


Ads by Google