2D Drawing Primitives

Similar documents
Graphics Programming. 1. The Sierpinski Gasket. Chapter 2. Introduction:

This library uses only GL functions but contains code for creating common objects and simplifying viewing.

Programming with OpenGL Part 3: Three Dimensions

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

CSC 8470 Computer Graphics. What is Computer Graphics?

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Programming with OpenGL Part 1: Background

Meshing and Geometry

Geometry Primitives. Computer Science Department University of Malta. Sandro Spina Computer Graphics and Simulation Group. CGSG Geometry Primitives

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

Programming using OpenGL: A first Introduction

Computer graphic -- Programming with OpenGL I

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12

CS130 : Computer Graphics. Tamar Shinar Computer Science & Engineering UC Riverside

Rendering. Part 1 An introduction to OpenGL

CSCI 4620/8626. Coordinate Reference Frames

Programming of Graphics

Filled Area Primitives. CEng 477 Introduction to Computer Graphics METU, 2007

Assignment 1. Simple Graphics program using OpenGL

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Computer Graphics (Basic OpenGL)

How shapes are represented in 3D Graphics. Aims and objectives By the end of the lecture you will be able to describe

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics I. Guoying Zhao 1 / 52

Computer Graphics. OpenGL

Computer Graphics and Visualization. Graphics Systems and Models

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL

Introduction to Computer Graphics with OpenGL/GLUT

Lecture 3 Advanced Computer Graphics (CS & SE )

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

OpenGL Primitives. Examples: Lines. Points. Polylines. void drawdot(glint x, GLint y) { glbegin(gl_points); glvertex2i(x,y); glend(); }

RECITATION - 1. Ceng477 Fall

Three Main Themes of Computer Graphics

CS130 : Computer Graphics Lecture 2: Graphics Pipeline. Tamar Shinar Computer Science & Engineering UC Riverside

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

CS 432 Interactive Computer Graphics

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

CMSC427 Final Practice v2 Fall 2017

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

Scan Conversion of Polygons. Dr. Scott Schaefer

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York

void drawdot(glint x, GLint y) { glbegin(gl_points); glvertex2i(x,y); glend();

Graphics Programming

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

pine cone Ratio = 13:8 or 8:5

Geometry Shaders. And how to use them

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

CS 4204 Computer Graphics

OPENGL AND GLSL. Computer Graphics

Draw the basic Geometry Objects. Hanyang University

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

OUTLINE. Hierarchical Models Z-Fighting Primitives Besides Triangles Back Face Culling

CGT 581 G Geometric Modeling Surfaces (part I)

9. Three Dimensional Object Representations

COS340A Assignment 1 I Pillemer Student# March 25 th 2007 p1/15

a triangle with all acute angles acute triangle angles that share a common side and vertex adjacent angles alternate exterior angles

Lecture 4 of 41. Lab 1a: OpenGL Basics

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY CS2401 COMPUTER GRAPHICS QUESTION BANK

三維繪圖程式設計 3D Graphics Programming Design 第三章三維繪圖狀態設定和幾何元件繪製嘉大資工系盧天麒

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

AutoCAD DWG Drawing Limitations in SAP 3D Visual Enterprise 9.0 FP03

Modeling. Simulating the Everyday World

Graphics and Visualization

Time: 3 hours Max. Marks: 80. Note: Answer FIVE full questions, choosing one full question from each module.

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 24 Solid Modelling

MPM1D Page 1 of 6. length, width, thickness, area, volume, flatness, infinite extent, contains infinite number of points. A part of a with endpoints.

Until now we have worked with flat entities such as lines and flat polygons. Fit well with graphics hardware Mathematically simple

Computer Graphics. Anders Hast. måndag 25 mars 13

Computer Graphics 1. Chapter 2 (May 19th, 2011, 2-4pm): 3D Modeling. LMU München Medieninformatik Andreas Butz Computergraphik 1 SS2011

Mrs. Daniel s Geometry Vocab List

AutoCAD DWG Drawing Limitations in SAP 3D Visual Enterprise 9.0 FP02

Introduction to OpenGL

Fractal Gaskets: Reptiles, Hamiltonian Cycles, and Spatial Development

CSCI 4620/8626. Computer Graphics Attributes of Graphics Primitives (Chapter 5)

Section 9.5. Tessellations. Copyright 2013, 2010, 2007, Pearson, Education, Inc.

Rasterization, or What is glbegin(gl_lines) really doing?

Copyright 2009 Pearson Education, Inc. Chapter 9 Section 7 - Slide 1 AND

CHAPTER 1 Graphics Systems and Models 3

Lecture 6: Fractals from Iterated Function Systems. He draweth also the mighty with his power: Job 24:22

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science

Introduction to OpenGL Week 1

Objectives. Image Formation Revisited. Physical Approaches. The Programmer s Interface. Practical Approach. Introduction to OpenGL Week 1

Rasterization: Geometric Primitives

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

Section 1-1 Points, Lines, and Planes

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

Chapter 3. Sukhwinder Singh

Elementary Planar Geometry

ME 111: Engineering Drawing. Geometric Constructions

From curves to surfaces. Parametric surfaces and solid modeling. Extrusions. Surfaces of revolution. So far have discussed spline curves in 2D

CURRICULUM CATALOG. GSE Geometry ( ) GA

Rendering Subdivision Surfaces Efficiently on the GPU

Graphics (Output) Primitives. Chapters 3 & 4

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

EXAMINATIONS 2017 TRIMESTER 2

Math 366 Lecture Notes Section 11.4 Geometry in Three Dimensions

Transcription:

THE SIERPINSKI GASKET We use as a sample problem the drawing of the Sierpinski gasket an interesting shape that has a long history and is of interest in areas such as fractal geometry. The Sierpinski gasket is an object that can be defined recursively and randomly; in the limit, however, it has properties that are not at all random. We start with a two dimensional version, but as we will later, the three-dimensional version is almost identical. Suppose that we start with three points in space. As long as the points are not collinear, they are the vertices of a unique triangle and also define a unique plane. We assume that this plane is the plane z = 0 and that these points, as specified in some convenient coordinate system,1 are (x1,y1,0), (x2,y2,0 ), and (x3,y3,0) the construction proceeds as follows: (Gasket 2D algorithm) : 1. Pick an initial point (x, y, z) at random inside the triangle. 2. Select one of the three vertices at random. 3. Find the location halfway between the initial point and the randomly selected vertex. 4. Display this new point by putting some sort of marker, such as a small circle, at the corresponding location on the display. 5. Replace the point at (x, y, z) with this new point. 6. Return to step 2. Thus, each time that we generate a new point, we display it on the output device. This process is illustrated in Figure, where p0 is the initial location, and p1 and p2 are the first two locations generated by our algorithm. 1

Sierpinski Gasket 2

PRIMITIVES AND ATTRIBUTES OpenGL supports two classes of primitives: geometric primitives and image, or raster primitives. Geometric primitives are specified in the problem domain and include points, line segments, polygons, curves, and surfaces. Because geometric primitives exist in a two- or three-dimensional space, they can be manipulated by operations such as rotation and translation. In addition, they can be used as building blocks for other geometric objects using these same operations. Raster primitives, such as arrays of pixels, lack geometric properties and cannot be manipulated in space in the same way as geometric primitives. 3

The primitives and their type specifications include the following: Points (GL_POINTS) Each vertex is displayed at a size of at least one pixel. line segments (GL_LINES) The line-segment type causes successive pairs of vertices to be interpreted as the endpoints of individual segments. Note that successive segments usually are disconnected because the vertices are processed on a pairwise basis. Polylines (GL_LINE_STRIP, GL_LINE_LOOP) If successive vertices (and line segments) are to be connected, we can use the line strip, or polyline form. Many curves can be approximated via a suitable polyline. If we wish the polyline to be closed, we can locate the final vertex in the same place as the first, or we can use the GL_LINE_ LOOP type, which will draw a line segment from the final vertex to the first, thus creating a closed path. Polygon Basics : Line segments and polylines can model the edges of objects, but closed objects also may have interiors. Usually we reserve the name polygon for an object that has a border that can be described by a line loop but also has a well-defined interior. Polygons play a special role in computer graphics because we can display them rapidly and use them to approximate arbitrary surfaces. The performance of graphics systems is characterized by the number of polygons per second that can be rendered. We can render a polygon in a variety of ways: We can render only its edges; we can render its interior with a solid color or a pattern; and we can render or not render the edges. Although the outer edges of a polygon are defined easily by an ordered list of vertices, if the interior is not well defined, then the list of vertices may not be rendered at 4

all or rendered in an undesirable manner. Three properties will ensure that a polygon will be displayed correctly: It must be simple, convex, and flat. Polygon Types in OpenGL Polygons (GL_P0LYGON) The edges are the same as they would be if we used line loops. Successive vertices define line segments, and a line segment connects the final vertex to the first. The interior is filled according to the state of the relevant attributes. Triangles and Quadrilaterals (GL_TRIANGLES, GL_QUADS) These objects are special cases of polygons. Successive groups of three and four vertices are interpreted as triangles and quadrilaterals, respectively. Using these types may lead to a rendering more efficient than that obtained with polygons. Strips and Fans (GL_TRIANGLE_STRIP, GL_QUAD_STRIP, GL_TRIANGLE_FAN) These objects are based on groups of triangles or quadrilaterals that share vertices and edges. In the triangle strip, for example, each additional vertex is combined with the previous two vertices to define a new triangle (Figure 2.14). For the quad_strip, we combine two new vertices with the previous two vertices to define a new quadrilateral. A triangle fan is based on one fixed point. The next two points determine the first triangle, and subsequent triangles are formed from one new point, the previous point, and the first (fixed) point. 5

POLYGONS AND RECURSION The output from our gasket program above shows considerable structure. If we were to run the program with more iterations, then much of the randomness in the image would disappear. Examining this structure, we see that regardless of how many points we generate, there are no points in the middle. If we draw line segments connecting the midpoints of the sides of the original triangle, then we divide the original triangle into four triangles, the middle one containing no points (see Figure below). 6

Looking at the other three triangles, we see that we can apply the same observation to each of them; that is, we can subdivide each of these triangles into four triangles by connecting the midpoints of the sides, and each middle triangle will contain no points. This structure suggests a second method for generating the Sierpinski gasket one that uses polygons instead of points and does not require the use of a random number generator. One advantage of using polygons is that we can fill solid areas on our display. Our strategy is to start with a single triangle, to subdivide it into four smaller triangles by bisecting the sides, and then to remove the middle triangle from further consideration. We repeat this procedure on the remaining triangles until the size of the triangles that we are removing is small enough about the size of one pixel that we can draw the remaining triangles. We can implement the process that we just described through a recursive program. We start its development with a simple function that draws a single triangular polygon given three arbitrary vertices: void triangle(glfloat *a, GLfloat *b, GLfloat *c) { glvertex2fv(a); glvertex2fv(b); glvertex2fv(c); } Suppose that the vertices of our original triangle are given by the following array: GLfloat v[3][2]; Then the midpoints of the sides are given by the array m [3] [3], which can be computed using the following code: 7

for(j=0; j<2; j++) m[0] [j] = (v[0] [j]+v[l] [j])/2.0; for(j=0; j<2; j++) m[l] [j] = (v[0] [j]+v[2] [j])/2.0; for(j=0; j<2; j++) m[2] [j] = (v[l ] [j]+v[2] [j])/2.0; With these six locations, we can use triangle to draw the three triangles formed by (v[0], m[0], m[l]); (v[2], m[l], m[2]); and (v[l], m[2], m[0]). We do not simply want to draw these triangles; we want to subdivide them. Hence, we make the process recursive. We define a recursive function divide_triangle(float *a, float *b, float *c, int k) that will draw the triangles only if k is zero. Otherwise, it will subdivide the triangle specified by a, b, and c and decrease k. 8