CGMB214: Introduction to Computer Graphics

Slides:



Advertisements
Similar presentations
Circle Drawing Asst. Prof. Dr. Ahmet Sayar Kocaeli University
Advertisements

CS 450: COMPUTER GRAPHICS DRAWING ELLIPSES AND OTHER CURVES SPRING 2015 DR. MICHAEL J. REALE.
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Larry F. Hodges (modified by Amos Johnson) 1 Design of Line, Circle & Ellipse Algorithms.
Let Maths take you Further…
Section 11.6 – Conic Sections
2D Output Primitives Graphics packages provide basic operations (called primitive operations) to describe a scene in terms of geometric structures. The.
Raster conversion algorithms for line and circle
Section 1.1 The Distance and Midpoint Formulas. x axis y axis origin Rectangular or Cartesian Coordinate System.
Chapter 3 Graphics Output Primitives
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Circle Drawing algo..
Solving Equations. Is a statement that two algebraic expressions are equal. EXAMPLES 3x – 5 = 7, x 2 – x – 6 = 0, and 4x = 4 To solve a equation in x.
Angles and Polar Coordinates. Angles Angles are a way to describe the difference in slope of two intersecting lines Vertex Angle.
1 CS 430/536 Computer Graphics I Circle Drawing and Clipping Week 3, Lecture 6 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent.
Dr. S.M. Malaek Assistant: M. Younesi
WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition.
Scan Conversion Line and Circle
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING ELLIPSES AND OTHER CURVES SPRING 2015 DR. MICHAEL J. REALE.
Larry F. Hodges 1 Design of Line and Circle Algorithms.
CHAPTER 9 CONIC SECTIONS.
Slide 5- 1 Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Unit #4 Conics. An ellipse is the set of all points in a plane whose distances from two fixed points in the plane, the foci, is constant. Major Axis Minor.
Slide 9- 1 Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
1 Circle Drawing Algorithms Pictures snagged from
Graphics Output Primitives
CGMB214: Introduction to Computer Graphics
ELLIPSE GENERATING ALGORITHMS 1. DEFINITION Ellipse is an elongated circle. Elliptical curves can be generated by modifying circle-drawing procedures.
MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS
November 18, We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle.
Slide Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Midpoint Circle Algorithm
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
Descriptive Geometry. Introduction  What is Descriptive Geometry? →It is the study of points, lines, and planes in space to determine their locations.
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
Instructor: Dr. Shereen Aly Taie If (P>0)
Conics. Conic Sections - Definition A conic section is a curve formed by intersecting cone with a plane There are four types of Conic sections.
Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Write Bresenham’s algorithm for generation of line also indicate which raster locations would be chosen by Bresenham’s algorithm when scan converting.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Copyright © 2011 Pearson Education, Inc. Conic Sections CHAPTER 13.1Parabolas and Circles 13.2Ellipses and Hyperbolas 13.3Nonlinear Systems of Equations.
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
1 Computer Graphics –Lect 03 Graphics Output Primitives Chapter – 3 of Hearn & Baker using OPENGL.
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Primitive graphic objects
Scan Conversion or Rasterization
Raster Graphics.
MID-POINT CIRCLE ALGORITHM
Parametric equations Parametric equation: x and y expressed in terms of a parameter t, for example, A curve can be described by parametric equations x=x(t),
Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm)
Scan Conversion or Rasterization
Lecture 05: Mid-point Ellipse algorithm Dr. Manal Helal – Fall 2014
Chapter Three Part I Output Primitives CS 380.
Topics in Analytic Geometry
Scan Conversion of Circles
Chapter 3 Conics 3.4 The Ellipse MATHPOWERTM 12, WESTERN EDITION
Allah says Say, "Allah created cattle for you. In them you find warmth and benefit and from them you eat. In them there is beauty for you when you bring.
Chapter 3 Conics 3.4 The Ellipse MATHPOWERTM 12, WESTERN EDITION
Scan Conversion (From geometry to pixels)
Chapter 3 Graphics Output Primitives
The Hyperbola Week 18.
Section 11.6 – Conic Sections
OUTPUT PRIMITIVES / DISPLAY TECHNIQUES
Presentation transcript:

CGMB214: Introduction to Computer Graphics Topic 4 Graphics Output Primitives (II)

Objectives To understand circle-drawing algorithms and line function

Other Output Primitives Circle Ellipse Curves

Circles Is a set of points from a given distance of r from center position (xC, yC). Is divided into 4 quadrants and 8 octants Symmetrical is used to reduce the number of calculations r (xC, yC)

Circles Cartesian Coordinates Midpoint Circle Algorithm Polar Coordinates

Cartesian Coordinates Also known as square root method Distance relationship expressed by the Pythagorean theorem in Cartesian coordinates as: (x-xc)2 – (y-yc)2 = r2 So, when stepping along the x axis in units intervals from xc to xc+ r and calculate the corresponding y co-ordinate with

Cartesian Coordinates y (x, y) r yc x xc

Cartesian Coordinates y = yc r2 – (xc-x)2 Given xc=10, yc=10, r=9 First point is at (10,19) Second point (x): y=10 (92 – (10-9)2) y=18.94, y=1.05 Third point (x): y=10 (92 – (10-8)2) y=18.77, y=1.22 Fourth point (x): y=10 (92 – (10-7)2) y=18.48, y=1.51 Fifth point (x): y=10 (92 – (10-6)2) y=18.06, y=1.93 Sixth point (x): y=10 (92 – (10-5)2) y=17.48, y=2.52 Seventh point (x): y=10 (92 – (10-4)2) y=16.70, y=3.29 Eight point (x): y=10 (92 – (10-3)2) y=15.65, y=4.34 Ninth point (x): y=10 (92 – (10-2)2) y=14.12, y=5.87 Tenth point (x): y=10 (92 – (10-1)2) y=10 The process will repeat for increasing x y 10 x 10

Cartesian Coordinates Disadvantages: Considerable amount of calculation (squares and square roots) Spacing between pixel is not uniform around the circle Based on the upper octant (between y axis and 45o line), circles increases faster along x axis compared to y axis. Since we are stepping along x axis, pixels with successive x co-ordinate positions can have the same y coordinate – reduce or no gap In the lower octant , the circle increases faster along the y axis compared to x axis. Pixels with successive y co-ordinates need to have the same x co ordinates to avoid gaps. Since , we are using x axis in unit of intervals, so each pixel has a unique y-coordinates – bigger gap.

Polar Coordinates Also known as Trigonometric Functions The equation of a circle is written in the polar coordinates r and  as  x = xc + r.cos y = yc + r.sin  x and y are the coordinates of a point on the circumference, i.e the end point of a line drawn from the centre of the circle to the circumference – the radius.

Polar Coordinates Example: Given P(2,2) is a center point of a circle, draw the circle with radius = 4 x=2+4(cos 0) = 6 y=2+4(sin 0)= 2 x=2+4(cos 45) = 4.8 y=2+4(sin 45)= 4.8 x=2+4(cos 90) = 2 y=2+4(sin 90)= 6 x=2+4(cos 135) =-0.8 y=2+4(sin 135)= 4.8 x=2+4(cos 180) = -2 y=2+4(sin 180)= 2 x=2+4(cos 225) =-0.8 y=2+4(sin 225)=-0.8 x=2+4(cos 270) = 2 y=2+4(sin 270)= -2 x=2+4(cos 315) = 4.8 y=2+4(sin 315)= -0.8

Polar Coordinates 7 6 3 5 4 2 4 3 2 5 1 1 -1 6 8 -2 7 -2 -1 1 2 3 4 5 -1 6 8 -2 7 -2 -1 1 2 3 4 5 6 7

Bresenham Algorithm (Mid Point Algorithm) To avoid rounding where incrementing integer for calculation is faster and more efficient. Center is not always at (0,0) In this algorithm, parameter P is used to determine the y co-ordinate of the next pixel to plot. Decision parameter P is based on circle function f that determines whether pixel is inside the boundary on the circle boundary outside the circle boundary fcircle = x2 + y2 – r2

Bresenham Algorithm (Mid Point Algorithm) Step along the x axis in unit intervals (k) from k=0 to k=r Plot the first point (0,r) From (0,r) then we need to decide whether to plot on (xk+1,yk) or (xk+1, yk-1) The decision parameter P is the circle function evaluated at the mid-point between these two pixels. P = fcircle(xk+1,yk – 0.5)

Bresenham Algorithm (Mid Point Algorithm) If P < 0 The mid-point is inside the boundary, so the pixel at (xk+1,yk) is closer to the circle boundary and should be plotted. P is then incremented by 2(x) + 1. If P= 0 or P > 0 The mid-point is outside or on the circle boundary. So the pixel at (xk+1,yk-1) is closer to the circle boundary and need to be plotted. P is then incremented by 2(x-y) + 1.

Bresenham Algorithm (Mid Point Algorithm) We only need to calculate the values on the border of the circle in the first octant. The other values may be determined by symmetry. Assume a circle of radius r with center at (0,0). Procedure Circle_Points(x,y :Integer); Begin Plot(x,y); Plot(y,x); Plot(y,-x); Plot(x,-y); Plot(-x,-y); Plot(-y,-x); Plot(-y,x); Plot(-x,y) End; (a,b) (b,a) (a,-b) (b,-a) (-a,-b) (-a,b) (-b,-a) (-b,a)

Ellipses An ellipses is an elongated circle and can be drawn with modified circle drawing algorithm. An ellipse has set of fixed points (foci) that will have a constant total of distance from all the points on the boundary. An ellipse has 2 axes Major: straight line running through the two foci and the long axis. Minor: straight line running through the centre that bisects the major axis – the short axis.

Ellipses Ellipse symmetry Ellipses are symmetrical between the four quadrants. Ellipses drawing algorithm only need to calculate the pixels for one quadrant. The general ellipse algorithm in Cartesian co-ordinates is Ax2 + By2 + Cxy + Dx + Ey + F = 0 As for circles, algorithms that use Cartesian or polar co-ordinates are computationally expensive.

Mid-Point Ellipses Algorithm A modification of the mid-point circle algorithm Incremental integer calculations. Calculations are easier if: the circle is centered on the origin (0,0) points are placed in the correct position by adding xc to the x co-ordinates and y, to the y co-ordinates. ie performing a translation the major and minor axes are aligned to be parallel with x and y axes. ellipses are drawn at the correct angle by rotating the points to their correct position.

Mid-Point Ellipses Algorithm A decision parameter P is used to determine the y co-ordinate of the next pixel or plot. Decision parameter P is based on ellipse function f that determines whether a pixel is inside the ellipse boundary on the ellipse boundary outside the ellipse boundary

Mid-Point Ellipses Algorithm fellipse(x,y) < 0 if(x,y) is inside the ellipse boundary = 0 if(x,y) is on the ellipse boundary > 0 if(x,y) is outside the ellipse boundary. Need to divide the quadrant into two regions and process the pixel in each region separately In region 1 the ellipse increases faster along the x axis than y axis In region 2 the ellipse increases faster along the y axis than x axis Plot the first point (0,r)

Mid-Point Ellipses Algorithm Region 1: Step along the x axis in unit intervals (k) until the boundary between region 1 and region 2. If we have just plotted pixel(xk,yk), the choices for the next pixel to plot are (xk + 1, yk) and (xk + 1, yk– 1) The decision parameter P is the ellipse function evaluated at the mid-point between these two pixels. P=fellipse(xk+1 , yk – 0.5)

Mid-Point Ellipses Algorithm The initial value of the decision parameter in Region 1 p0 = r2y –r2xry + 0.25r2x

Mid-Point Ellipses Algorithm If Pk < 0 The mid-point is inside the ellipse boundary so the pixel at (xk + 1, yk) ) is closer to the ellipse boundary and should be plotted. Pk+1 = Pk + 2r2yxk+1 + r2y If Pk=0 or Pk>0 The mid-point is outside or on the ellipse boundary pixel at (xk+1,yk-1) is closer to the ellipse boundary and should be plotted. Pk+1 = P k + 2r2yxk+1 - 2r2xyk+1 + r2y

Mid-Point Ellipses Algorithm Region 2: Step along the y axis in unit intervals (k) for the remainder of the curve until y = 0 If we have just plotted pixel (xk,yk), the choices for the next pixel to plot are (xk,yk-1) and (xk+1,yk-1) The decision parameter P is the ellipse function evaluated at the mid-point between these two pixels. P = fellipse(xk+0.5 , yk –1)

Mid-Point Ellipses Algorithm The circle algorithm can be generalized to work for an ellipse but only four way symmetry can be used. All the points in one quadrant must be computed. Since Bresenham's algorithm is restricted to only one octant, the computation must occur in two stages. The changeover occurs when the point on the ellipse is reached where the tangent line has a slope of ±1. In the first quadrant, this is when the x and y coordinates are both at 0.707 of their maximum.

Other Curves Conic sections such as a and b are constants Parabolas determined by initial velocity v0 and acceleration g (gravity) y = yo + a(x-xo)2 + b(x-x0) a and b are constants determined by parameter t (time – in second) x = x0 + vx0t y = y0 + vyot – 0.5gt2 V Velocity Yo G .gravity Vo Xo

Speed Improvement Parallel Line Algorithms Line Segmentation Algorithm DDA and Bresenham determine pixel positions sequentially and faster with parallel computer Line Segmentation Algorithm n processors Divide line into n segments and assign pixel position calculations of one segment to one processor.

Speed Improvement Bounding Rectangle Algorithm Assign 1 processor to 1 pixel inside the bounding rectangle (needs x. y processors) Each processor calculates the perpendicular distance of the pixel from the line Plot point if the distance of the pixel from the line is less than or equal to the line thickness.

Speed Improvement Parallel Curve Algorithm Circle Like straight lines, parallel curve algorithms use segmentation and bounding rectangles. Curve segmentation Circle Divide the circular arc the upper octant into sub-arc segments Assign the pixel calculations for each segment to a different processor.

Speed Improvement Ellipse Divide the elliptical arc in the first quadrant into sub-arc segment Assign the pixel calculations for each segment to a different processor