Docsity

2D Graphics Algorithms: Line and Circle Drawing, Antialiasing, and Fill Area Algorithms - , Lecture notes of Computer Science

Partial preview of the text

Download 2D Graphics Algorithms: Line and Circle Drawing, Antialiasing, and Fill Area Algorithms - and more Lecture notes Computer Science in PDF only on Docsity!

1

2D Graphics Algorithms

• Output Primitives

• Line Drawing Algorithms

  • (^) DDA Algorithm
  • (^) Midpoint Algorithm
  • (^) Bersenhem’s Algorithm

• Circle Drawing Algorithms

  • (^) Midpoint Circle Algorithm

• Antialising

• Fill-Area Algorithms

2

Output Primitives

  • (^) These are the basic objects out of which

a graphics display is created.

  • (^) Describes the geometry of objects and –

typically referred to as geometric

primitives.

  • (^) Examples: point, line, text, filled region,

images, quadric surfaces, spline curves

  • (^) Each of the output primitives has its

own set of attributes.

Output Primitives

  • (^) Lines
    • (^) Attributes: Color, Thickness, Type glLineWidth(p); glBegin(GL_LINES); glVertex2d(x1, y1); glVertex2d(x2, y2); glVertex2d(x3, y3); glVertex2d(x4, y4); glEnd()

Output Primitives

• Polylines (open)

  • (^) A set of line segments joined end to end.
  • (^) Attributes: Color, Thickness, Type glLineWidth(p); glBegin(GL_LINE_STRIP); glVertex2d(x1, y1); glVertex2d(x2, y2); glVertex2d(x3, y3); glVertex2d(x4, y4);

Output Primitives

• Polygons

  • (^) A set of line segments joined end to end.
  • (^) Attributes: Fill color, Thickness, Fill pattern Note: Polygons can be filled. glBegin(GL_POLYGON); glVertex2d(x1, y1); glVertex2d(x2, y2); glVertex2d(x3, y3); glVertex2d(x4, y4); glEnd()

8

Output Primitives

• Text

  • (^) Attributes: Font, Color, Size, Spacing,

Orientation.

  • (^) Font:
    • (^) Type (Helvetica, Times, Courier etc.)
    • (^) Size (10 pt, 14 pt etc.)
    • (^) Style (Bold, Italic, Underlined)

10 Output Primitives Output Primitive Attributes Point Size Color Line Thickness (1pt, 2pt … ) Type (Dashed, Dotted, Solid) Color Text Font (Arial, Courier, Times Roman … ) Size (12pt, 16pt ..) Spacing Orientation (Slant angle) Style (Bold, Underlined, Double lined) Color Filled Region Fill Pattern Fill Type (Solid Fill, Gradient Fill) Fill Color Images Color Depth (Number of bits/pixel)

11

Line Drawing Algorithms

Line Drawing - Analytical Method

y y x x y x

b a

m

b a

c a ma

y x

y=mx+c

a x bx A(a x ,a y

B(b x ,b y

  • (^) Directly based on the analytical equation of a line.
  • (^) Involves floating point multiplication and addition
  • (^) Requires round-off function. double m = (double)(by-ay)/(bx-ax); double c = ay - max;* double y; int iy; for (int x=ax ; x <=bx ; x++) { y = mx + c;* iy = round(y); setPixel (x, iy); }

Line Drawing - Analytical Method

Current Pixel (x k , y k

To find (x k+ , y k+!

x

k+

= x

k

y k+

  • (^) Assumes that the next pixel to be set is on the next column of pixels (Incrementing the value of x !)
  • (^) Not valid if slope of the line is large.

Incrementing along x

Digital Differential Analyzer Algorithm is an incremental algorithm. Assumption: Slope is less than 1 (Increment along x). Current Pixel = (x k , y k

(x k , y k ) lies on the given line. y k = m.x k

  • c Next pixel is on next column. x k+ = x k

Next point (x k+ , y k+ ) on the line y k+ = m.x k+

  • c = m (x k +1) +c =mx k
  • m +c = y k
  • m Given a point (x k , y k ) on a line, the next point is given by x k+ = x k

y k+ = y k

  • m

Line Drawing - DDA

x

k+

= x

k

y

k+

= Either y

k

or y

k

Midpoint algorithm is an incremental algorithm

Midpoint Algorithm

Assumption: Slope < 1 Current Pixel

Candidate Pixels Current Pixel ( xk, yk) Midpoint Line Coordinates of Midpoint = ( x k +1, y k

( x k +1, y k

( x k +1, y k

Midpoint Algorithm -

Notations