OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

Similar documents
UNIT 2 GRAPHIC PRIMITIVES

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

Rasterization: Geometric Primitives

CPSC / Scan Conversion

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm

Chapter 8: Implementation- Clipping and Rasterization

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

Line Drawing. Foundations of Computer Graphics Torsten Möller

Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

CS 130. Scan Conversion. Raster Graphics

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

From Ver(ces to Fragments: Rasteriza(on

MODULE - 4. e-pg Pathshala

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

Output Primitives. Dr. S.M. Malaek. Assistant: M. Younesi

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization.

Chapter - 2: Geometry and Line Generations

Rendering. A simple X program to illustrate rendering

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

Unit 2 Output Primitives and their Attributes

Scan Conversion. Drawing Lines Drawing Circles

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

Output Primitives Lecture: 4. Lecture 4

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

CS 543: Computer Graphics. Rasterization

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

CSCI 4620/8626. Coordinate Reference Frames

CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

Einführung in Visual Computing

Topic #1: Rasterization (Scan Conversion)

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

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by:

Computer Graphics. Lecture 2. Doç. Dr. Mehmet Gokturk

Computer Graphics. - Rasterization - Philipp Slusallek

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

1 Introduction to Graphics

Department of Computer Sciences Graphics Fall 2003 (Lecture 2) Pixels

GRAPHICS OUTPUT PRIMITIVES

Lab Manual. Computer Graphics. T.E. Computer. (Sem VI)

Chapter 3. Sukhwinder Singh

Scan Converting Circles

UNIT -8 IMPLEMENTATION

Polar (BC Only) They are necessary to find the derivative of a polar curve in x- and y-coordinates. The derivative

Computer Graphics D Graphics Algorithms

OUTPUT PRIMITIVES. CEng 477 Introduction to Computer Graphics METU, 2007

(Refer Slide Time: 00:03:51)

To sketch the graph we need to evaluate the parameter t within the given interval to create our x and y values.

COMP371 COMPUTER GRAPHICS

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

Line Drawing Week 6, Lecture 9

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

1.1 Functions. Cartesian Coordinate System

EFFICIENT INTEGER ALGORITHMS FOR THE GENERATION OF CONIC SECTIONS

Computer Graphics D Graphics Algorithms

13.1 2/20/2018. Conic Sections. Conic Sections: Parabolas and Circles

Graphics (Output) Primitives. Chapters 3 & 4

Rasterization and Graphics Hardware. Not just about fancy 3D! Rendering/Rasterization. The simplest case: Points. When do we care?

Realtime 3D Computer Graphics Virtual Reality

Points and lines. x x 1 + y 1. y = mx + b

Computer Graphics 7 - Rasterisation

CS Rasterization. Junqiao Zhao 赵君峤

Display Technologies: CRTs Raster Displays

Lecture 5. If, as shown in figure, we form a right triangle With P1 and P2 as vertices, then length of the horizontal

Rendering. A simple X program to illustrate rendering

Efficient Plotting Algorithm

RASTERIZING POLYGONS IN IMAGE SPACE

Chapter 1. Linear Equations and Straight Lines. 2 of 71. Copyright 2014, 2010, 2007 Pearson Education, Inc.

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves

form. We will see that the parametric form is the most common representation of the curve which is used in most of these cases.

A New Line Drawing Algorithm Based on Sample Rate Conversion

Overview of Computer Graphics

MET71 COMPUTER AIDED DESIGN

9.1 Linear Inequalities in Two Variables Date: 2. Decide whether to use a solid line or dotted line:

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

Conic Sections. College Algebra

, minor axis of length 12. , asymptotes y 2x. 16y

Painter s HSR Algorithm

MEI Desmos Tasks for AS Pure

CS 450: COMPUTER GRAPHICS RASTERIZING LINES SPRING 2016 DR. MICHAEL J. REALE

Sketching graphs of polynomials

Multivariable Calculus

R asterisation. Part I: Simple Lines. Affine transformation. Transform Render. Rasterisation Line Rasterisation 2/16

EF432. Introduction to spagetti and meatballs

UNIT 3 EXPRESSIONS AND EQUATIONS Lesson 3: Creating Quadratic Equations in Two or More Variables

Module 3: Stand Up Conics

Pre-Calculus Guided Notes: Chapter 10 Conics. A circle is

Rendering approaches. 1.image-oriented. 2.object-oriented. foreach pixel... 3D rendering pipeline. foreach object...

Unit 3 Higher topic list

Unit 12 Topics in Analytic Geometry - Classwork

Graphics System. Processor. Output Display. Input Devices. Frame Buffer. Memory. Array of pixels. Resolution: # of pixels Depth: # of bits/pixel

Algebra II Chapter 10 Conics Notes Packet. Student Name Teacher Name

Computer Graphics Lecture Notes

Surface shading: lights and rasterization. Computer Graphics CSE 167 Lecture 6

I Internal Examination (Model Paper) B.Tech III Year VI semester, Computer Science & Engineering

Math 231E, Lecture 34. Polar Coordinates and Polar Parametric Equations

COMPUTER AIDED ENGINEERING DESIGN (BFF2612)

Rasterization. CS 4620 Lecture Kavita Bala w/ prior instructor Steve Marschner. Cornell CS4620 Fall 2015 Lecture 16

CS602 MCQ,s for midterm paper with reference solved by Shahid

Unit 2: Function Transformation Chapter 1. Basic Transformations Reflections Inverses

Transcription:

D Graphics Primitives Eye sees Displays - CRT/LCD Frame buffer - Addressable pixel array (D) Graphics processor s main function is to map application model (D) by projection on to D primitives: points, lines, polygons (coloured and shaded) Projection is followed by Scan-conversion. D Parametric Attributes Display List D polygons OpenGL Graphics System Evaluator D polygons Pixel Operations Per- Vertex D points Texture Memory D pixels colours Rasterization Per- Fragment D pixels colours blending clipping Frame Buffer D Graphics Primitives D Primitives: lines, circles... Co-ordinate Conventions Drawing D Primitives Scan Conversion: filled area primitives Attributes of D Graphics Primitives Antialiasing Drawing D Graphics Primitives D Primitives: Lines Circles Ellipses Other Curves Polygons: empty and filled - Characters General Mathematical D Primitives Parametric Equations (x(t), y(t)) Line x(t)=x +t(x x ) y(t)=y +t(y y ) Implicit Equations < inside F(x, y)= > outside f (x,y)=ax + by + c a=y y b=x x c=x y x y Scan Conversion Scan Conversion also known as Rasterization Can be thought of in two equivalent ways: - As a Convolution between an ideal mathematical function (infinitely thin line) and an object the size and shape of a pixel followed by sampling at the pixel positions - Pixels have finite area, output is overlap of pixel with curve

Co-ordinate Conventions What convention is used for coordinate system?. Like square Graph paper: pixels are unit squares that tile the plane with corners at [(x,y),(x +,y + )]. Pixels centred on integer co-ordinates: mathematical. Co-ordinate Conventions Graph Paper I will use this convention, point is at [,] Point at x =, y = Pixel Centred Drawing Lines Basic line drawing Digital Differential Analyser (DDA) Accelerating Basic Line Drawing Uses the simplest expression for a straight line Considers entire line Technique requires floating point and function call in inner-most loop of algorithm which is slow Care needed with end points to get length correct Basic Line Drawing Basic Line Drawing x = # $ " % x = # $ " % ( [ ]) ( [ ]) y i = mx i + c x i, Round y i where m = "y "x and x i, Floor y i +. y i = "y "x x i + c c = y i # "y "x x i

Basic Line Drawing Example x = # $ " % x = # $ " % m = "y "x = c = y "y "x x = Basic Line Drawing Example i x i y i y i +."........ Basic Line Drawing x = # $ " % x = # $ " % Basic Line Drawing Issues NB If we plot the final end point of the line the length would be x = and y = instead of the required x = and y = " Plot pixels interior to the line path Each iteration requires a floating point multiply, add, and the use of the Floor function. Line Drawing: DDA Digital Differential Analyser Solves a parametric equation by solving a differential equation In general the parametric form can be converted to a differential equation using its Taylor expansion: d f = f (t + dt) f (t + dt)= f (t) + f (t)dt + f (t) dt + K DDA for straight lines Polynomial of order n has at most n non-zero derivatives. For straight lines, y(x) = mx + c, this is effectively: dy = y( x + dx) y( x) = y "( x)dx rearranging : y(x + dx) = y(x) + y "(x).dx Remember that: m = y x

DDA for Straight lines DDA Line Drawing If we let dx=, and recognise y (x) as, m, the line gradient: y k+ = mx k + + c = m(x k +) + c = y k + m x = # $ " % x = # $ " % DDA DDA algorithm for arbitrary slopes Result is identical to Basic method Core of calculation requires only an addition + Floor operation Uses only gradient, no explicit use of intercept So far slope has been: m - m : step in x and use: y k+ = y k + m m > : reverse roles of x and y (step in y) and use: x k+ = x k + m FAST Recursive For each point on the line uses: - integer add - or integer increments - integer comparison Uses decision variable Deal with slopes m to start with yk + yk B d A d xk xk + Just drawn shaded Pixel Which pixel do we draw next, A or B?

y co-ordinate of ideal mathematical line at position (xk+) is: - y = m(xk + ) + c Distance to pixel centre below line is: - d = y - yk = m(xk + ) + c - yk Distance to discrete point above line is: - d = (yk + ) - y = (yk + ) - m(xk + ) - c Difference (d - d) of distances: - d - d = m(xk + ) - yk + c - By substituting, m = "y/"x, and rearranging, we can get and integer only expression DEFINE Decision variable to be: - pk = "x (d - d) Substituting for (d - d) : - pk = "y xk - "x yk + K where K is a constant. Decision variable: - pk = "y xk - "x yk + K pk has the same sign as (d - d), since "x is +ve. pk < # choose yk+ = yk pk $ # choose yk+ = yk + Decision variable at next point: - pk+ = "y xk+ - "x yk+ + K Take difference of decision variable at current and next point (eliminates K): - pk+ - pk = "y (xk+ - xk) - "x (yk+ - yk) Giving recurrence relation for pk+: - pk+ = pk + "y - "x (yk+ - yk), - since (xk+ - xk) = Recurrence relation for decision pk+ = pk + "y - "x (yk+ - yk) Which can take on two forms, either: - If (pk < ) # choose yk+ = yk - pk+ = pk + "y (since (yk+ - yk)=) Or - - If pk $ # choose yk+ = yk + pk+ = pk + "y - "x (since (yk+ - yk)=) Initialising Decision Variable: Recall from earlier pk = "y xk - "x yk + K where K = "y + "x(c - ) Since: - c = y - x "y/"x# c "x = "x y - x "y We can substitute for c "x above with k= p = "y - "x

Setup. Input endpoints,. Store left endpoint in (x, y). Draw pixel at (x, y). Calculate constants: "x, "y, ( "y), ( "y- "x). Initialise decision variable: p = "y - "x Loop For each xk, from k = to k = "x- - If ( pk < ) Draw pixel at (xk +, yk) - pk+ = pk + ( "y) - Else Draw pixel at (xk +, yk+) - pk+ = pk + ( "y - "x) Bresenham Line Example Bresenham Line Example x = # $ " % x = # $ " % x = # $ " % x = # $ " % Bresenham Line Example x = # $ " % x = # $ " % Generalising Line to Arbitrary Orientations So far have considered lines with slope between and + (first octant) Need to consider implications for algorithm of arbitrary slopes of lines

Slope > Interchange roles of x and y axes Calculate x values of line points Step along y direction in unit increments Could also revise algorithm to plot points in either direction - Both x and y decrease as line is generated - Decide on convention for d = d (plot lower or upper, but must be consistent) Procedure is similar Slope < One co-ordinate decreases as the other increases For negative slope < - again axes are swapped - Decrement y axis co-ordinate - Calculate new x co-ordinate Special Cases Horizontal lines and Vertical lines can be detected at the initialisation stage (before the Bresenham inner loop) and written directly into the Frame Buffer Drawing Circles Basic Circle drawing Accelerating Circle s by exploiting symmetry Midpoint () Circle Details Circle Drawing Techniques Circle is defined by: - (x - xc) + (y - yc) = r Solving this gives: - y = yc ± %(r - (x - xc)) Computation of square root Step in x Also need to swap axes to step in y rather than x Step in y Circle Drawing Techniques Calculate points along a circular boundary by stepping in equal increments of angle: Polar parametric form: - x = xc + r cos - y = yc + r sin Again considerable computation of trigonometric expressions

Reducing computation by Symmetry of circles Can work in quadrants Even more efficient to exploit octants Need only compute one eighth of circle points: Work in single octant Variation of algorithm more easily extended to ellipses and other curves Need to set up a decision variable to determine which pixel is next plotted around circular path Use implicit circle function: f (x,y) = x + y r f (x,y) = x + y r Implicit function for a circle: f(x, y) <, inside circle f(x, y) =, on the circle - f(x, y) >, outside circle These tests are performed on the midpoint between two candidate next points y k y k - x k x k +?? Work in third quadrant Need to keep points plotted by algorithm internal to circle in graph paper coordinate convention Work in sixth Octant and exploit symmetry yk + yk A B?? Work in single octant xk - xk

: Decision parameter In previous slide have just drawn pixel at (xk, yk), which is next pixel B is at (xk -, yk), or pixel A is at (xk -, yk + )? Decision variable is circle function evaluated at the midpoint: p k = f (x k +.,y k + ) = f (x k.,y k + ) p k = (x k.) + (y k + ) r Decision Parameter If p k < - Midpoint is INSIDE circle - Plot point B Else - Midpoint is OUTSIDE circle - Plot point A Decision Parameter We have an expression for already, then p k+ = (x k+.) + (y k+ + ) r And because x k+ = x k p k+ = (x k.) + (y k+ + ) r p k Decision Parameter Get a recurrence relation for the decision parameter by forming: p k+ p k We then rearrange this to get an expression for: p k+ =p k (x k + ) + (y k+ + y k )(y k+ y k ) + (y k+ y k ) NB (y k+ y k ) will either be + or Initialising Decision Parameter p = f (, r) =(.) + ( r + ) r =. r For integer radius we can take the floor of this to be: p = r To write down the algorithm we have noted that when: y k+ = y k + p k+ =p k (x k + ) + (y k+ + y k )(y k+ y k ) + (y k+ y k ) Simplifies to: p k+ = p k + (y k x k ) + Since: y k+ = y k + and y k+ y k =

IF pk < midpoint INSIDE xk+ = xk - yk+ = yk SetCirclePoints(xk+, yk +) pk+ = pk - xk + ELSE midpoint OUTSIDE xk+ = xk - yk+ = yk + SetCirclePoints(xk+, yk+) pk+ = pk + (yk - xk) + - - - Circle R= - - - - - Circle R = - - - - - - - - - - - - - - - - - - - Circle R= - - - - - - - - - - - Conics Circles are a member of a group of functions, the conics, their general form is: Ax + By +Cxy + Dx + Ey + F = Particular conic is given by: - B - AC < Ellipse or Circle - B - AC = Parabola - B - AC > Hyperbola Hearn and Baker, p -