1 / 31

CGMB214: Introduction to Computer Graphics

CGMB214: Introduction to Computer Graphics. Topic 4 Graphics Output Primitives (II). Objectives. To understand circle-drawing algorithms and line function. Other Output Primitives. Circles. r. ( xC , yC ). Circles. Cartesian Coordinates. Also known as square root method

yuma
Download Presentation

CGMB214: Introduction to Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Objectives To understand circle-drawing algorithms and line function

  3. Other Output Primitives

  4. Circles r (xC, yC)

  5. Circles

  6. 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

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

  8. 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

  9. 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.

  10. 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.

  11. 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

  12. Polar Coordinates 7 6 3 5 4 2 4 3 2 5 1 1 0 -1 6 8 -2 7 -2 -1 0 1 2 3 4 5 6 7

  13. 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

  14. 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)

  15. 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.

  16. (-b,a) (b,a) (-a,b) (a,b) (-a,-b) (a,-b) (b,-a) (-b,-a) BresenhamAlgorithm (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;

  17. 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.

  18. 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.

  19. 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 xcto 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.

  20. 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

  21. 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)

  22. 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)

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

  24. 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

  25. 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)

  26. 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.

  27. Other Curves • Conic sections such as • 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

  28. Speed Improvement • Parallel Line Algorithms • DDAand Bresenhamdetermine 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.

  29. 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.

  30. Speed Improvement • Parallel Curve Algorithm • 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.

  31. 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

More Related