Unit 2 - Output Primitives and Their Attributes
Unit 2 - Output Primitives and Their Attributes
y = m.x
y = m (since x = 1)
y k+1 - y k = m
y k+1 = y k + m (Eq.1)
Here ‘k’ is integer value that starts from 1 and always increases by 1.
Here ‘m’ is float value so we have to round off the ‘y’ value to nearest
integer value.
y = m.x
x = y / m
x = 1 / m (since y = 1)
x k+1 - x k = 1 / m
x k+1 = x k + (1 / m) (Eq. 2)
Summary:
In short, for | m | < 1 we have to increase or de crease the x value by 1
depends on the value of x. If x is positive then we have to increase its
and if x is negative then we have to decrease its value. Then we have to
calculate the value of y based on (Eq. 1). If y is positive then y value
is incremented by ‘m’ and if y is negative then y is decremented by ‘m’.
Similar case is possible for |m| > 1 but here the action of x and y is
interchanged.
Algorithm:
1. Read (x1, y1) and (x2, y2) (First and second coordinate of line)
2. dx = x2 – x1;
dy = y2 – y1;
3. If absolute(dx) > absolute(dy) then
s = absolute(dx)
Else
s = absolute(dy)
End if
4. xinc = dx / s
yinc = dy / s
5. x = x1;
y = y1;
Consider the line having positive slope and slope value is less than 1.
First the pixel is plotted at co-ordinates (x k , y k ). Then the x value is
always increased by 1 and find out whether the y value is incremented by
1 or not. So the next pixel position is either (x k +1,y k ) or (x k +1, y k +1).
yk +1
d2
y
d1
yk
xk xk +1
d1 = y - y k
d1 = m (x k + 1) + b - y k (From eq. (3.1))
and d2 = (y k + 1) – y
d2 = (y k + 1) – m (x k + 1) – b
d1 – d2 = m (x k + 1) + b - y k - [y k + 1) – m (x k + 1) – b]
d1 – d2 = 2m (x k + 1) - 2y k + 2b – 1
d1 – d2 = [2 y (x k + 1) / x] - 2y k + 2b – 1
x (d1-d2) = 2 y (x k + 1) – 2 x y k + 2 x b – x
x (d1-d2) = 2 y x k + 2 y - 2 x y k + 2 x b – x
x (d1-d2) = 2 y x k - 2 x y k + 2 x b – x + 2 y (3.2)
In eq. (3.2) last three terms are constant so we can put some constant b’
in place of them. Also we put x (d1-d2) = p k as decision parameter.
p k = 2 y x k - 2 x y k + b’ (3.3)
Here from eq. (3.5) we can take the decision whether we have to
increase y value or not. If decision parameter p is < 0 then d1 < d2 that
means y is more closer to y k so we have to plot (x k ,y k ) and if decision
parameter p is > 0 then d1 > d2 that means y is more closer to (y k + 1)
so we have to plot (x k , y k + 1).
Here we are calculating the decision parameter value from previous value
but for initial point we can determine decision parameter by:
p 0 = 2 y - x (3.6)
Here we have only considered the case of positive slope with less than or
equal to 1. Similarly we can derive the equation for the slope greater
than 1 but for that purpose the action of x and y is interchanged.
1. Read (x1, y1) and (x2, y2) (First and second coordinate of line)
2. dx = absolute(x2 – x1)
dy = absolute(y2 – y1)
3. p = 2 * dy – dx
V.P. & R.P.T.P SCIENCE COLLEGE, VV NAGAR 4|Page
US05CBCA02 – Computer Graphics Unit - 2
4. if x1 > x2 then
x start = x2
y start = y2
x end = x1
y end = y1
else
x start = x1
y start = y1
x end = x2
y end = y2
end if
5. setpixel(x start , y start , color)
6. Repeat steps 7 to 9 for i = x start to x end
7. x start = x start + 1
8. if p < 0 then
p = p+ 2 * dy
else
if (((y2-y1)/(x2-x1)) > 1) then
p = p+ 2*(dy – dx)
y start = y start + 1
else
p = p+ 2*(dy – dx)
y start = y start – 1
end if
endif
9. setpixel(x start , y start , color)
10. Exit
A circle is defined as the set of points that are all at a distance ‘r’, called the
radius, from a centre position (x c , y c ).
yk
yk - 1
yk - 2
xk xk+1 xk+2
p k = f (x k + 1, y k – ½)
= (x k + 1) 2 + (y k – ½) 2 – r 2
= (x k + 1) 2 + y k 2 – y k + ¼ – r 2 (2)
If p k < 0 then the midpoint is inside the circle so y k is closer to the circle
boundary so our point is (x k + 1, y k ) otherwise the point is (x k + 1, y k –
1). Similarly we have next decision parameter is p k+1 .
If p k < 0 then
y k+1 = y k
p k+1 = p k + 2(x k + 1) + (y k 2 – y k 2 ) – (y k – y k ) + 1
p k+1 = p k + 2x k+1 + 1 (5)
else
y k+1 = y k – 1
p k+1 = pk + 2(x k + 1) + ((y k – 1) 2 – y k 2 ) – ((y k – 1) – y k ) + 1
= pk + 2x k+1 + (-2y k + 2) + 1
= pk + 2x k+1 - 2(y k - 1) + 1
p k+1 = pk + 2x k+1 - 2y k+1 + 1 (6)
p0 = f(1, r – ½)
= 1 + (r – ½) 2 – r 2
= 1 + r2 – r + ¼ - r2
= 1 – r + ¼
= 5/4 – r (7)
Algorithm:
There are two basic approaches to area filling on raster systems. One
way to fill an area is to determine the overlap intervals for scan lines that
cross the area. Another method for area filling is to star t from a given
interior position and paint outward from this point until we encounter the
specified boundary conditions. The scan-line approach is typically used in
general graphics packages to fill polygons, circles, ellipses, and other
simple curves. Fill methods starting from an interior point are useful with
more complex boundaries and in interactive painting systems
For each scan line crossing a polygon is then sorted from left to right, and
the corresponding frame buffer positions between each intersection pair are set to
the specified color. These intersection points are then sorted from left to right ,
and the corresponding frame buffer positions between each intersection pair are
set to specified color.
In the given example, four pixel intersections define stretches from x=10 to x=14
and x=18 to x=24
A scan Line passing through a vertex intersects two polygon edges at that
position, adding two points to the list of intersections for the scan Line
In the given example , scan Line y intersects five polygon edges and the scan
Line y’ intersects 4 edges although it also passes through a vertex y' correctly
identifies internal pixel spans ,but need some extra processing
The topological difference between scan line y and scan line y’ is identified by
noting the position of the intersecting edges relative to the scan line. For Scan
line y, the two intersecting edges sharing a vertex are on opposite sides of the
scan line. But for scan line y’, the two intersecting edges are both above the scan
line. Thus, the vertices that require additional processing are those that have
connecting edges on opposite sides of scan line.
We can identify these vertices by tracing around the polygon boundary either in
clock-wise or anti-clockwise order and observing the relative changes in vertex y
coordinates as we move from one edge to the next.
Otherwise, the shared vertex represents a local extremum (min. or max.) on the
polygon boundary, and the two edge intersections with the scan line passing
through that vertex can be added to the intersection list.
One way to resolve this is also to shorten some polygon edges to split those
vertices that should be counted as one intersection. Non horizontal edges around
the polygon boundary in the order specified, either clockwise or anti-clockwise.
When the end point y coordinates of the two edges are increasing, the y value of
the upper endpoint for the current edge is decreased by 1. When the endpoint y
values are monotonically decreasing, we decrease the y coordinate of the upper
endpoint of the edge following the current edge.
Algorithm:
1. Set y to the smallest y coordinate that has an entry in the ET; i.e, y for the
first nonempty bucket.
3.1 Move from ET bucket y to the AET those edges whose y_min = y
(entering edges).
3.2 Remove from the AET those entries for which y = y_max (edges not
involved in the next scanline), the sort the AET on x (made easier
because ET is presorted).
3.5 For each nonvertical edge remaining in the AET, update x for the new y.
4. Exit
1. Odd-Even Method
There are two methods for going to neighbouring pixels from the current
position. For the given point, its neighbouring four p oints, that is, left,
right, top and bottom, are tested. This method is known as 4-
connected.
4-connected 8-connected
Algorithm:
1. colour = getpixelcolour(x,y)
2. if (colour != bordercolour and colour != fillcolour), t hen
(a) setpixelcolour (x, y, fillcolour)
(b) BoundaryFill(x+1, y, fillcolour, bordercolour)
(c) BoundaryFill(x–1 , y, fillcolour, bordercolour)
(d) BoundaryFill(x, y+1, fillcolour, bordercolour)
(e) BoundaryFill(x, y–1 , fillcolour, bordercolour)
3. Return
For 8-connected, call the BoundaryFill() function four more times with the
coordinate values of the diagonal points, that is, the right -top (x+1,
y+1), the right-bottom (x+1, y-1), the left-top (x-1, y+1) and the left-
bottom (x-1, y-1).
We start from a specific interior point (x, y) and reassign the pixels with
current interior colour with the specified fill colour. Using either 4 -
connected or 8-connected approach, we pass through pixel positions until
all interior points have been repainted.
V.P. & R.P.T.P SCIENCE COLLEGE, VV NAGAR 12 | P a g e
US05CBCA02 – Computer Graphics Unit - 2
Algorithm:
1. colour = getpixelcolour(x,y)
2. if (colour == oldcolour), then
(a) setpixelcolour (x, y, fillcolour)
(b) FloodFill(x+1, y, fillcolour, oldcolour)
(c) FloodFill(x–1 , y, fillcolour, oldcolour)
(d) FloodFill(x, y+1, fillcolour, oldcolour)
(e) FloodFill(x, y–1 , fillcolour, oldcolour)
3. Return
Character Generation
Letters, numbers and other characters can be displayed in a variety of
sizes and styles. The design style for a set of ch aracters is called a
Typeface or Font.
Typefaces or Fonts can be divided into two broad groups: Serif and Sans
Serif. Serif type has small lines at the ends of the main character strokes
(called accents), while Sans Serif does not have accents. Serif type is
generally more readable, that is, it is easier to read in large amount of
texts. On the other hand, the individual characters in sans -serif type are
easier to identify. So, Sans-Serif type is said to be more legible and is
good for labelling and short heading.
Bitmap fonts are simplest to define and display. The character grid only
needs to be mapped to a frame-buffer position. But bitmap fonts require
more space. It is possible to generate different sizes and other
variations, such as bold, italics, etc., but usually the results are not
good.
Attributes
The features or characteristics of an output primitive are known as
Attribute. In other words, any parameter that affects the way a
primitive is to be displayed is known as Attribute. Some attributes, such
as colour and size, are basic characteristics of primitive. Some attributes
control the basic display properties of primitives. For example, lines can
be dotted or dashed, thin or thick. Areas can be filled with one colour or
with multiple colours pattern. Text can appear from left to right, slanted
or vertical.
Line Attributes:
Basic attributes of a straight line are its type, its width, and its colour. In
some graphics packages, line can also be displayed using selected pen or
brush options.
1. Line Type: The line type attribute includes solid lines, dashed lines,
and dotted lines. We modify the line drawing algorithm to generate such
lines by setting the length and space. A dashed line could be displayed by
generating spaces that is equal to length of solid part. A dotted line can
be displayed by generating very short dashes with spacing eq ual to or
greater than the dash size. Similar methods are used to produce other
line-type variations.
remain approximately same for any line angle. For this, we can adjust the
pixel number according to line slope.
2. Line Width: A line with more width can be displayed as parallel lines
on a video monitor. In raster lines, a standard widt h line is generated
with single pixels at each point. Width lines are displayed by plotting
additional pixels along next parallel line paths. For lines with slope less
than 1, we can display thick lines by plotting a vertical length of pixels at
each x position along the line. Similarly, for lines with slope greater than
1, we can plot thick lines with horizontal widths for each point.
One kind of line cap is the Butt Cap. It is obtained by adjusting the end
positions of lines so that the thick line is displayed with square ends that
are perpendicular to the line. Another line cap is the Round Cap
obtained by adding a filled semicircle to each butt cap. The semicircle has
diameter equal to thickness of line. The third type of line cap is the
Projecting Square Cap. Here, the butt cap is extended to half of line
width.
Thick Lines drawn with (a) Butt Cap (b) Round Cap and (c) Projecting Square Cap
V.P. & R.P.T.P SCIENCE COLLEGE, VV NAGAR 15 | P a g e
US05CBCA02 – Computer Graphics Unit - 2
Other fill options include specifications for the edge type, edge width and
edge colour. These attributes are same as the line attributes. That is, we
can display polygon edges as dotted, dashed, thick or of different
colours, etc.
Soft Fill
We may want to fill area again due to 2 reasons:
• It is blurred (unclear) when painted first time, or
• It is repainting of a color area that was originally filled with
semitransparent brush, where current color is then mixture of the
brush color and the background color “ behind” the area.
So that the fill color is combined with the background colors are referred
to as Soft-fill.
Character Attributes:
The appearance of displayed characters is controlled by attributes such
as font, size, colour and orientation. Attributes can be set both for entire
character strings and for individual characters, known as Marker symbols.
1. Text Attributes: There are many text options available, such as font,
colour, size, spacing, and orientation.
Text Style: The characters in a selected font can also be displayed in
various underlining styles (solid, dotted, dashed, double), in bold, in
italics, s h a d o w style, etc. Font options can be made available as
predefined sets of grid patterns or as character sets designed with
lines and curves.
Text Colour: Colour settings for displayed text are stored in the
system attribute list and transferred to the frame buffer by character
loading functions. When a character string is displayed, the current
colour is used to set pixel values in the frame buffer corresponding to
the character shapes and position.
Text Size: We can adjust text size by changing the overall
dimensions, i.e., width and height, of characters or by changing only
the width. Character size is specified in Points, where 1 point is
0.013837 inch or approximately 1/72 inch. Point measurements specify
the size of the Character Body. Different fonts with the same point
specifications can have different character sizes depending upon the
design of the font.
Topline Kern
Capline
H
Character Body
Character
Height Baseline
Bottomline
f q Descenders
Orientation
at
nt
nt
at
rie
io
n
O
g
n
i
r
t
s A text displayed with the four text-path
options
gnirts String
s
t
r
i
n
g
top
cap
half
TEXT ALIGNMENT base
bottom
Declaration: This material is developed only for the reference for lectures in the
classrooms. Students are required library reading for more study. This study
material compiled from Book “Computer Graphics by Donald Hearn & M. Pauline
Baker, PHI, 1995