0% found this document useful (0 votes)
7 views

CHAPTER 4 (2)

Chapter Four covers geometry and line generation in computer graphics, detailing algorithms for drawing lines and circles, including Bresenham's and DDA algorithms. It also discusses polygons, filling techniques, text rendering, and color models used in graphics. Key concepts include line thickness, styles, and the mathematical foundations for plotting shapes and curves.

Uploaded by

miki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

CHAPTER 4 (2)

Chapter Four covers geometry and line generation in computer graphics, detailing algorithms for drawing lines and circles, including Bresenham's and DDA algorithms. It also discusses polygons, filling techniques, text rendering, and color models used in graphics. Key concepts include line thickness, styles, and the mathematical foundations for plotting shapes and curves.

Uploaded by

miki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 57

CHAPTER FOUR

GEOMETRY AND LINE GENERATION


Geometry and Line Generation
 Point and Lines, Bresenham’s algorithm Generating
Line, & Circle
 Plotting General Curves
 Line Thickness & Line Style
 Polygons
 Filling
 Text and Characters
 Colors

2
LINE GENERATION/DROWING ALGORITHM
• A line connects two points.
• It is a basic element in graphics.
• To draw a line, you need two points between
which you can draw a line.
• we refer the one point of line as X0, Y0 and
the second point of line as X1, Y1.
Cont..
• Line drawing algorithm
– Programmer specifies (x,y) values of end pixels
– Need algorithm to figure out which intermediate
pixels are on line path
– Pixel (x,y) values constrained to integer values
– Actual computed intermediate line values may be
floats
– Rounding may be required. E.g. computed point
(10.48, 20.51) rounded to (10, 21)
Cont..
Cont..
LINE EQUASION
• Slope-intercept line equation (Cartesian equation)

𝑦 = 𝑓(𝑥) = 𝑚𝑥 + 𝑏
written as

• where m is the slope and b is the y-intercept. This is


a function of only x and it would be useful to make
this equation written as a function of both x and y.
Using algebraic manipulation and recognition that
the slope is the "rise over run" or dy/dx then
Cont..
• Given two end points (x0,y0), (x1, y1), how to
compute m and b?
Cont..
Numerical example of finding slope

M=𝐵𝑦−𝐴𝑦 = 96−41 = 55 = 0.5392


m: (Ax, Ay) = (23, 41), (Bx, By) = (125,96)

𝐵𝑥−𝐴x 125−23 102


DDA Algorithm

• DDA algorithm is an incremental scan conversion


method.
• Here we perform calculations at each step using
the results from the preceding step.
• The characteristic of the DDA algorithm is to take
unit steps along one coordinate and compute the
corresponding values along the other coordinate.
• The unit steps are always along the coordinate
of greatest change
Cont..
Cont..
Cont..
DDA Line Drawing Algorithm Pseudocode
compute m;
if m < 1:
{
float y = y0; // initial value
for(int x = x0;x <= x1; x++, y += m)
setPixel(x, round(y));
}
else // m > 1
{
float x = x0; // initial value
for(int y = y0;y <= y1; y++, x += 1/m)
setPixel(round(x), y);
}
Bresenham’s LINE GENERATION
• The Bresenham algorithm is another incremental
scan conversion algorithm.
• The big advantage of this algorithm is that, it
uses only integer calculations.
• Moving across the x axis in unit intervals and at
each step choose between two different y
coordinates.
Cont..
Cont..
Cont.…
• In the diagram the starting point is blue dot(xk,yk).
• There are two points A and B are there on the grid
line
• The line intersects the gird at point C (x,y).
• The AC=d2 and BC= d1 with the values of d1 and
d2 the next point will be selected.
• Here a new term is introduced which is decision
parameter(pk).
• This parameter will take the decision which grid
line will be selected yk or yk +1.
Cont..
Cont..
Cont..
cont..
Cont..
Cont..
Cont.Cont.
Cont..
Cont..
Cont..
Circle Generation Algorithm
• A circle is a set of all points in a plane that are at a
given distance from a given point, centre.
• Drawing a circle on the screen is a little complex than
drawing a line.
• There are two popular algorithms for generating a
circle:
o Bresenham’s Algorithm and
o Midpoint Circle Algorithm.
• These algorithms are based on the idea of determining
the subsequent points required to draw the circle.
• Let us discuss the algorithms in detail: The equation of
circle is X2 + Y2 = r2 , where r is radius.
Cont..
• So, we can write a simple circle drawing algorithm by
solving the equation for y at unit x intervals using:

• However, unsurprisingly this is not a brilliant solution!


• Firstly, the resulting circle has large gaps where the slope
approaches the vertical Secondly, the calculations are
not very efficient
• The square (multiply) operations
• The square root operation
Cont..
• We need a more efficient, more accurate
solution
• The first thing we can notice to make our
circle drawing algorithm more efficient is that
circles centred at (0, 0) have eight-way
symmetry
Cont..
Cont..
Cont..

=
Cont..
Cont.…
Cont.…
Cont.…
Point and Lines
• Points
glBegin(GL_POINTS);
Vertex2i(100,50);
• Lines
glBegin(GL_LINES);
Vertex2i(100,50);
Vertex2i(200,250);

Computer Graphics 45
Plotting curves
– Plotting General Curves
Syntax
drawArc(Point Centre,
Float Radius,
a
Float Angle_a, b

Float Angle_b)

Computer Graphics 46
Line thickness
– Line Thickness (Width)
Syntax
void glLineWidth( GLfloat width);
• width Specifies the width of rasterized lines. The initial
value is 1.

Computer Graphics 47
Line style
– Line Stipple
Syntax
void glLineStipple(Glint factor, Glushort pattern);
• sets the current stippling patten for lines
– the pattern argument is a 16 bit series of 0s and 1s, and it is
repeated as necessary
– the pattern can be stretched out by using factor (factor is
clamped between 1 and 256)
glLineStipple(1, 0x3F07);
glEnable(GL_LINE_STIPPLE);

Computer Graphics 48
Con…
polygons
– Polygon
• Polygon refer to an object that has border that can be described
by a line loop.
• Types
• GL_Polygon (more than four angles in an object)
• GL_Quads (four different angles in an object)
• GL_Triangles (three different angles in an object)

50
Polygons (contd…)
• Attributes in Polygons
– STRIP and FAN
o GL_TRIANGLES_STRIP
o GL_TRIANGLES_FAN
o GL_QUAD_STRIP

Computer Graphics 51
filling
• Filling Area
• A basic fill-area attribute provided by a general graphics
library is the display style of the interior.
void glShadeModel(GLenum mode);
• mode Accepted values are GL_FLAT and GL_SMOOTH. The
initial value is GL_SMOOTH.

Computer Graphics 52
Text in graphics
• Text
• Combination or collection of characters which is meaningful
called text(s).
• There are two forms of text is available in Graphics,
– Stoke Text (from predefined FONT)
glutStrokeCharacter(GLUT_STROKE_ROMAN, Char Text);
(Roman Font)
– Raster Text (creating with Vertices)
glutBitmapCharacter(GLUT_BITMAP_8_BY_13 , Char Text);
( 8 x 13 size)

53
Colors
• Color
• Color is one of the most interesting aspects of both human
perception and computer graphics.
– Subtractive -CMY Model
– Additive - RGB Model

54
Cont..
• Color combinations that result from combining
primary colors available in the two situations additive
color and subtractive color.

a): RGB is used to specify additive color. (b): CMY is used to specify subtractive
color
Color values
Red Green Blue Color as Output

1.0 0.0 0.0 Red


0.0 1.0 0.0 Green
0.0 0.0 1.0 Blue
1.0 1.0 0.0 Yellow
0.0 1.0 1.0 Cyan
1.0 0.0 1.0 Magenta
1.0 1.0 1.0 White
0.0 0.0 0.0 Black

56
End of Chapter 4

You might also like