0% found this document useful (0 votes)
40 views32 pages

Ending Polylines in Bluebeam

The document discusses computer graphics and multimedia. It introduces topics like output primitives, line drawing algorithms, rasterization, and Bresenham's line algorithm. It provides details about points, lines, circles, ellipses and their generation. It also discusses digital differential analyzer algorithm and Bresenham's line algorithm for rasterization.

Uploaded by

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

Ending Polylines in Bluebeam

The document discusses computer graphics and multimedia. It introduces topics like output primitives, line drawing algorithms, rasterization, and Bresenham's line algorithm. It provides details about points, lines, circles, ellipses and their generation. It also discusses digital differential analyzer algorithm and Bresenham's line algorithm for rasterization.

Uploaded by

Saranya D
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer Graphics and Multimedia

COMPUTER GRAPHICS AND MULTIMEDIA


UNIT-I
Output Primitives: Points and Lines – Line-Drawing algorithms – Loading frame Buffer – Line
function – Circle-Generating algorithms – Ellipse-generating algorithms.
Attributes of Output Primitives: Line Attributes – Curve attributes – Color and Grayscale
Levels – Area-fill attributes – Character Attributes.

INTRODUCTION ABOUT COMPUTER GRAPHICS


Computer Graphic is the discipline of producing picture or images using a computer which
include modeling, creation, manipulation, storage of geometric objects, rendering, converting a
scene to an image, the process of transformations, rasterization, shading, illumination, animation
of the image, etc.
Computer Graphics has been widely used in graphics presentation, paint systems,
computer-aided design (CAD), image processing, simulation, etc. From the earliest text character
images of a non-graphic mainframe computers to the latest photographic quality images of a high
resolution personal computers, from vector displays to raster displays, from 2D input, to 3D input
and beyond, computer graphics has gone through its short, rapid changing history. From games to
virtual reality, to 3D active desktops, from unobtrusive immersive home environments, to
scientific and business, computer graphics technology has touched almost every concern of our
life. Before we get into the details, we have a short tour through the history of computer graphics

OUTPUT PRIMITIVES
Introduction
The basic elements constituting a graphic are called output primitives. Each output
primitive has an associated set of attributes, such as line width and line color for lines. The
programming technique is to set values for the output primitives and then call a basic function that
will draw the desired primitive using the current settings for the attributes. Various graphics
systems have different graphics primitives.
For example GKS defines five output primitives namely, polyline (for drawing contiguous
line segments), polymarker (for marking coordinate positions with various symmetric text
symbols), text (for plotting text at various angles and sizes), fill area (for plotting polygonal areas
with solid or hatch fill), cell array (for plotting portable raster images). At the same time GRPH1
has the output primitives namely Polyline, Polymarker, Text, Tone and have other secondary
primitives besides these namely, Line and Arrow
Points and Lines
In a CRT monitor, the electron beam is turned on to illuminate the screen phosphor at the
selected location. Depending on the display technology, the positioning of the electron beam
changes. In a random-scan (vector) system point plotting instructions are stored in a display list
and the coordinate values in these instructions are converted to deflection voltages the position the
electron beam at the screen locations. Low-level procedure for ploting a point on the screen at
(x,y) with intensity “I” can be given as
setPixel(x,y,I)
Computer Graphics and Multimedia

A line is drawn by calculating the intermediate positions between the two end points and
displaying the pixels at those positions.

LINE DRAWING ALGORITHM


The Cartesian slope intercept equation for a straight line is
Y=m.x + b
Where m represents slope of the line and b as the y intercept.

y1
y2

x1 X2

the two end points in the line segement at specified position(x 1,y1),and (x2,y2).
Slope m and y as
m = y2-y1,
x2-x1.
b = y1 - m.x1
for any given x interval ∆x along a line, we compute the corresponding y interval ∆y as
∆y=m ∆x
Similiarly,we can obtain the x interval ∆x to the corresponding ∆y as
∆x= ∆y/m
Computer Graphics and Multimedia

Rasterization
Rasterization is the process of converting a vertex representation to a pixel representation;
rasterization is also called scan conversion. Included in this definition are geometric objects such
as circles where you are given a center and radius.

 The digital differential analyzer (DDA) which introduces the basic concepts for
rasterization.
 Bresenham's algorithm which improves on the DDA.
Scan conversion algorithms use incremental methods that exploit coherence. An
incremental method computes a new value quickly from an old value, rather than computing the
new value from scratch, which can often be slow. Coherence in space or time is the term used to
denote that nearby objects (e.g., pixels) have qualities similar to the current object.
1. Digital Differential Analyzer (DDA) Algorithm

In computer graphics, a hardware or software implementation of a digital differential


analyzer (DDA) is used for linear interpolation of variables over an interval between start and end
point.

DDAs are used for rasterization of lines, triangles and polygons. In its simplest
implementation the DDA algorithm interpolates values in interval [(x start, ystart), (xend, yend)] by
computing for each xi the equations xi = xi−1+1, yi = yi−1 + Δy/Δx, where Δx = xend − xstart and Δy
= yend − ystart.

Digital Differential Analyzer (DDA) Algorithm:-


x

slope of the line y= m* x+b


y

In this algorithm, the line is sampled at unit intervals in one coordinate and find the corresponding
values nearest to the path for the other coordinate. For a line with positive slope less than one, x >
y (where x = x2-x1 and y = y2-y1).
Hence we sample at unit x=1 intervals and compute each successive y values as
yk+1=yk + m

For lines with positive slope greater than one, y > x. Hence we sample at unit y intervals and
compute each successive x values as
Xk+1=Xk +1/m
Since the slope, m, can be any real number, the calculated value must be rounded to the nearest
integer.
(xi , yi)
(xi , Round(yi))
Computer Graphics and Multimedia

positive slope left to right positive slope right to left all points are joint together

For a line with negative slope, if the absolute value of the slope is less than one, we make unit
increment in the x direction and calculate y values as

yk+1=yk - m
For a line with negative slope, if the absolute value of the slope is greater than one, we make unit
decrement in the y direction and calculate x values as

Xk+1=Xk +1/m
[Note :- for all the above four cases it is assumed that the first point is on the left and second point
is in the right.]
DDA Line Algorithm
void myLine(int x1, int y1, int x2, int y2)
{
int length,i;
double x,y;
double xincrement;
double yincrement;
length = abs(x2 - x1);
if (abs(y2 - y1) > length) length = abs(y2 - y1);
xincrement = (double)(x2 - x1)/(double)length;
yincrement = (double)(y2 - y1)/(double)length;
x = x1 + 0.5;
y = y1 + 0.5;
for (i = 1; i<= length;++i)
{
myPixel((int)x, (int)y);
Computer Graphics and Multimedia

x = x + xincrement;
y = y + yincrement;
}
}
[Link]'s line algorithm

The Bresenham line algorithm is an algorithm which determines which points in an n-


dimensional raster should be plotted in order to form a close approximation to a straight line
between two given points. It is commonly used to draw lines on a computer screen, as it uses only
integer addition, subtraction and bit shifting, all of which are very cheap operations in standard
computer architectures. It is one of the earliest algorithms developed in the field of computer
graphics. A minor extension to the original algorithm also deals with drawing circles.

While algorithms such as Wu's algorithm are also frequently used in modern computer
graphics because they can support antialiasing, the speed and simplicity of Bresenham's line
algorithm mean that it is still important. The algorithm is used in hardware such as plotters and in
the graphics chips of modern graphics cards. It can also be found in many software graphics
libraries. Because the algorithm is very simple, it is often implemented in either the firmware or
the hardware of modern graphics cards.

The label "Bresenham" is used today for a whole family of algorithms extending or
modifying Bresenham's original algorithm

The algorithm

The common conventions will be used: That pixel coordinates increase in the right and down
directions (e.g. that the pixel at (1,1) is directly above the pixel at (1,2)), andthat the pixel centers
have integer coordinates.

The endpoints of the line are the pixels at (x0, y0) and (x1, y1), where the first coordinate of
the pair is the column and the second is the row.

The algorithm will be initially presented only for the octant in which the segment goes
down and to the right (x0≤x1 and y0≤y1), and its horizontal projection x1 − x0 is longer than the
vertical projection y1 − y0 (the line has a slope whose absolute value is less than 1 and greater than
0.) In this octant, for each column x between x0 and x1, there is exactly one row y (computed by
the algorithm) containing a pixel of the line, while each row between y0 and y1 may contain
multiple rasterized pixels.

Bresenham's algorithm chooses the integer y corresponding to the pixel center that is
closest to the ideal (fractional) y for the same x; on successive columns y can remain the same or
increase by 1. The general equation of the line through the endpoints.
Computer Graphics and Multimedia

Since we know the column, x, the pixel's row, y, is given by rounding this quantity to the
nearest integer.

The slope (y1 − y0) / (x1 − x0) depends on the endpoint coordinates only and can be
precomputed, and the ideal y for successive integer values of x can be computed starting
from y0and repeatedly adding the slope.

In practice, the algorithm can track, instead of possibly large y values, a small error value
between −0.5 and 0.5: the vertical distance between the rounded and the exact y values for the
current x. Each time x is increased, the error is increased by the slope; if it exceeds 0.5, the
rasterization y is increased by 1 (the line continues on the next lower row of the raster) and the
error is decremented by 1.0.

In the following pseudocode sample plot(x,y) plots a point and abs returns absolute value:

function line(x0, x1, y0, y1)


int deltax := x1 - x0
int deltay := y1 - y0
real error := 0
real deltaerr := abs (deltay / deltax) // Assume deltax != 0 (line is not vertical),
// note that this division needs to be done in a way that preserves the fractional part
int y := y0
for x from x0 to x1
plot(x,y)
error := error + deltaerr
Computer Graphics and Multimedia

if error ≥ 0.5 then


y := y + 1
error := error - 1.0
Generalization

The version above only handles lines that descend to the right. We would of course like to
be able to draw all lines. The first case is allowing us to draw lines that still slope downwards but
head in the opposite direction. This is a simple matter of swapping the initial points if x0 > x1.
Trickier is determining how to draw lines that go up. To do this, we check if y0 ≥ y1; if so, we step
y by -1 instead of 1.

Lastly, we still need to generalize the algorithm to drawing lines in all directions. Up until
now we have only been able to draw lines with a slope less than one. To be able to draw lines with
a steeper slope, we take advantage of the fact that a steep line can be reflected across the line y=x to
obtain a line with a small slope. The effect is to switch the x and y variables throughout, including
switching the parameters to plot. The code looks like this:

function line(x0, x1, y0, y1)


boolean steep := abs(y1 - y0) > abs(x1 - x0)
if steep then
swap(x0, y0)
swap(x1, y1)
if x0 > x1 then
swap(x0, x1)
swap(y0, y1)
int deltax := x1 - x0
int deltay := abs(y1 - y0)
real error := 0
real deltaerr := deltay / deltax
int ystep
int y := y0
if y0 < y1 then ystep := 1 else ystep := -1
for x from x0 to x1
if steep then plot(y,x) else plot(x,y)
error := error + deltaerr
if error ≥ 0.5 then
y := y + ystep
error := error - 1.0

The function now handles all lines and implements the complete Bresenham's algorithm.

Optimization

The problem with this approach is that computers operate relatively slowly on fractional
numbers like error and deltaerr; moreover, errors can accumulate over many floating-point
additions. Working with integers will be both faster and more accurate. The trick we use is to
multiply all the fractional numbers (including the constant 0.5) in the code above by deltax, which
enables us to express them as integers. This results in a divide inside the main loop, however. To
deal with this we modify how error is initialized and used so that rather than starting at zero and
counting up towards 0.5, it starts at 0.5 and counts down to zero. The new program looks like this:
Computer Graphics and Multimedia

function line(x0, x1, y0, y1)


boolean steep := abs(y1 - y0) > abs(x1 - x0)
if steep then
swap(x0, y0)
swap(x1, y1)
if x0 > x1 then
swap(x0, x1)
swap(y0, y1)
int deltax := x1 - x0
int deltay := abs(y1 - y0)
int error := deltax / 2
int ystep
int y := y0
if y0 < y1 then ystep := 1 else ystep := -1
for x from x0 to x1
if steep then plot(y,x) else plot(x,y)
error := error - deltay
if error < 0 then
y := y + ystep
error := error + deltax

Remark: If you need to control the points in order of appearance (for example to print several
consecutive dashed lines) you will have to simplify this code by skipping the 2nd swap:

Function line(x0, x1, y0, y1)

boolean steep := abs(y1 - y0) > abs(x1 - x0)


if steep then
swap(x0, y0)
swap(x1, y1)
int deltax := abs(x1 - x0)
int deltay := abs(y1 - y0)
int error := deltax / 2
int ystep
int y := y0

int inc REM added


if x0 < x1 then inc := 1 else inc := -1 REM added

if y0 < y1 then ystep := 1 else ystep := -1


for x from x0 to x1 with increment inc REM changed
if steep then plot(y,x) else plot(x,y)
REM increment here a variable to control the progress of the line drawing
error := error - deltay
if error < 0 then
y := y + ystep
error := error + deltax
Computer Graphics and Multimedia

Simplification

It is further possible to eliminate the swaps in the initialisation by considering the error
calculation for both directions simultaneously:

function line(x0, y0, x1, y1)


dx := abs(x1-x0)
dy := abs(y1-y0)
if x0 < x1 then sx := 1 else sx := -1
if y0 < y1 then sy := 1 else sy := -1
err := dx-dy

loop
setPixel(x0,y0)
if x0 = x1 and y0 = y1 exit loop
e2 := 2*err
if e2 > -dy then
err := err - dy
x0 := x0 + sx
end if
if e2 < dx then
err := err + dx
y0 := y0 + sy
end if
end loop

In this method, developed by Jack Bresenham, we look at just the center of the pixels. We
determine d1 and d2 which is the "error", i.e., the difference from the "true line."

Steps in the Bresenham algorithm:


1. Determine the error terms
2. Define a relative error term such that the sign of this term tells us which pixel to choose
3. Derive equation to compute successive error terms from first
4. Compute first error term

Now the y coordinate on the mathematical line at pixel position xi+1 is calculated as
y = m(xi+1) + b
And the distances are calculated as
d1 = y - yi= m(xi+1) + b - yi
d2 = (yi+1) - y = yi +1 -m(xi +1) - b
Then
d1 - d2 = 2m(xi+1) - 2y + 2b -1
Now define pi = dx(d1 - d2) = relative error of the two pixels.

Note: pi < 0 if yi pixel is closer, pi >= 0 if yi+1 pixel is closer. Therefore we only need to know
the sign of pi .
ith m = dy/dx and substituting in for (d1 - d2) we get

pi = 2 * dy * xi - 2 * dx * yi + 2 * dy + dx * (2 * b - 1) (1)
Computer Graphics and Multimedia

Let C = 2 * dy + dx * (2 * b - 1)

Now look at the relation of p's for successive x terms.

pi+1 = 2dy * xi+1 - 2 * dx * yi+1 + C


pi+1 - pi = 2 * dy * (xi+1 - xi) - 2 * dx * ( yi+1 - yi)

with xi+1 = xi + 1 and yi+1= yi + 1 or yi

pi+1 = pi + 2 * dy - 2 * dx(yi+1 -yi)


Now compute p1 (x1,y1) from (1) , where b = y - dy / dx * x

p1 = 2dy * x1 - 2dx * y1 + 2dy + dx(2y1 - 2dy / dx * x1 - 1)


= 2dy * x1 - 2dx * y1 + 2dy + 2dx * y1 - 2dyx1 - dx
= 2dy - dx
if pi < 0, plot the pixel (xi+1, yi) and next decision parameter is pi+1 = pi + 2dy
else and plot the pixel (xi+1, yi+1) and next decision parameter is pi+1 = pi + 2dy - 2dx
Bresenham Algorithm for 1st octant:
1. Enter endpoints (x1, y1) and (x2, y2).
2. Display x1, y1.
3. Compute dx = x2 - x1 ; dy = y2 - y1 ; p1 = 2dy - dx.
4. If p1 < 0.0, display (x1 + 1, y1), else display (x1+1, y1 + 1)
5. if p1 < 0.0, p2 = p1 + 2dy, else p2 = p1 + 2dy - 2dx
6. Repeat steps 4, 5 until reach x2, y2.

Note: Only integer Addition and Multiplication by 2.


Notice we always increment x by 1.

For a generalized Bresenham Algorithm must look at behavior in different octants.

[Link] line algorithms


Take advantage of multiple processors.

 Given np processors, subdivide the line path into np Bresenham segments.

 For a line with slope 0  m  1 and leftpoint (x0,y0) the distance to the right endpoint
(left endpoint for next segment) is

 where

 x = width of the line

 xp is computed using integer division

 Numbering the segments, and the processors, as 0, 1, 2, …, np-1, starting x-


coordinate for the kth partition is

xk = x0 + kxp
Computer Graphics and Multimedia

i.e. x = 15 , np = 4 processors

Starting x-values at x0, x0 + 4, x0 + 8, x0 + 12

yp = mxp
At the kth segment, the starting y-coordinates is

yk = y0 + round(kyp)

 Also, the initial decision parameter for Bresenham’s algorithm at the start of the
kth subinterval is:

pk = (kxp)(2y) – round(kyp)(2x) + 2y – x

 Lines generated can have jagged or stair-step appearance, one aspect of


phenomenon called aliasing, caused by fact that pixels are integer coordinate points.

 Use anti-aliasing routines to smooth out display of a line by adjusting pixels


intensities along the line path.

 Each processor then calculates the pixel positions over its assigned subinterval
using the starting decision parameter value for that subinterval and the starting
coordinates (xk,yk).
 Another way to set up parallel algorithms on raster systems is to assign each
processor to a particular group of screen pixels. Assign each processor to 1 pixel
within some screen region. This approach can be adapted to line display by
assigning 1 processor to each of the pixels within the limits of the line coordinates
extends (bounding rectangle) and calculating the pixel distances from the line path.
Computer Graphics and Multimedia

The no: of pixels within the bounding box of the line is ∆x * ∆y. Perpendicular
distance d from the line to a pixel with coordinates (x,y) is calculated as,
d = Ax + By + C
where, A = -∆y / line length
B = ∆x / line length
C = x0∆y – y0∆x / line length
With line length = √(∆x2 + ∆y2)

 Once the constants A,B,C are calculated, the processor needs to perform 2
multiplications and 2 additions to compute the pixel distance d. A pixel is plotted
if d < a specified line thickness parameter. Instead of partitioning the screen
intosingle pixels, we can assign to each processor either a scanline or a column of
pixels depending on the line slope

LOADING THE FRAME BUFFER


 When straight line segments and other coordinate extends are scan converted for
display with a raster system, frame buffer positions must be calculated .
 Scan conversion algorithms generate pixel positions at successive unit intervals.
This allows using incremental methods to calculate frame buffer addresses
 Suppose the frame buffer array is addressed in row major order and that pixel
positions vary from (0,0) at the lower left screen corner to (xmax,ymax) at the top
right corner. For a bi-level system (1 bit per pixel) the frame buffer bit address for
pixel position (x,y) is calculated as
addr(x,y) = addr(0,0) + y(xmax +1) + x
 Moving across the scan line calculate the frame buffer address for the pixel
at(x+1,y) as the following offset from the address for position (x,y)
addr(x +1,y) = addr(x,y) + 1
 Stepping diagonally up to the next scanline from (x,y) we get the frame buffer
address of (x+1,y+1) with the calculation
addr(x +1,y+1) = addr(x,y) + xmax + 2
 where the constant xmax + 2 is pre computed once for all line segments.

LINE FUNCTION
A procedure for specifying straight-line segments can be set up in a number of different
forms. In PHIGS, GKS, and some other packages, the two-dimensionalline function is where
parameter n is assigned an integer value equal to the number of coordinate positions to be input,
and wcpoints is the array of input world coordinate values for line segment endpoints.
This function is used to define a set of n – 1 connected straight line segments. Because
series of connected line segments occur more often than isolated line segments in graphics
applications, polyline provides a more general line function. To display a single straight-line
segment, we set n -= 2 and list the x and y values of the two endpoint [Link] an example
Computer Graphics and Multimedia

of the use of polyline, the following statements generate two connected line segments, with
endpoints at (50, 103, (150, 2501, and (250,100):
wcPoints[ll .x = SO;
wcPoints[ll .y = 100;
wcPoints[21 .x = 150;
wc~oints[2l.y = 250;
wc~oints[3l.x = 250;
wcPoints[31 .y = 100;
polyline ( 3 , wcpoints);
Coordinate references in the polyline function are stated as absolute coordinate values.
This means that the values specified are the actual point positions in the coordinate system in use.
Some systems employ line (and point) functions with relative coordinate specifications. In
this case, coordinate values are stated as offsets from the last position referenced (called the current
position).
For example, if location(3,2) is the last position that has been referenced in an application
program, a relative coordinate specification of (2, -1) corresponds to an absolute position of (5,1).
An additional function is also available for setting the current position before the line routine is
summoned. With these packages, a user lists only the single pair of offsets in the line command.
This signals the system to display a line starting from the current position to a final position
determined by the offsets.
The current position is then updated to this final line position. A series of connected lines
is produced with such packages by a sequence of line commands, one for each line section to be
drawn. Some graphics packages provide options allowing the user to specify Line endpoints using
either relative or absolute coordinates.
Implementation of the polyline procedure is accomplished by first performing a series of
coordinate transformations, then malung a sequence of calls to a device-level line-drawing routine.
In PHIGS, the input line endpoints are actually specified in modeling coordinates, which are then
converted to world c eordinates.
Next, world coordinates are converted to normalized coordinates, then to device
coordinates. We discuss the details for carrying out these two dimensional coordinate
transformations in Chapter 6. Once in device coordinates, we display the plyline by invoking a
line routine, such as Bresenham's algorithm,n - 1 times to connect the n coordinate points.
Each successive call passes the c c ~ordinate pair needed to plot the next line section, where
the first endpoint of each coordinate pair is the last endpoint of the previous section. To avoid
setting the intensity of some endpoints twice, we could modify the line algorithm so that the last
endpoint of each segment is not plotted. We discuss methods for avoiding overlap of displayed
objects.

CIRCLE GENERATING ALGORITHM


Properties of Circles
Computer Graphics and Multimedia

The set of points in the circumference of the circle are all at equal distance r from the centre
(xc,yc) and its relation is given be pythagorean theorem as

(X –XC)2 + (Y-YC)2= r2

The points in the circumference of the circle can be calculated by unit increments in the x
direction from xc - r to xc+ r and the corresponding y values can be obtained as

Y=Yc±√𝐫2- (xc-x)2

The major problem here is that the spacing between the points will not be [Link] can be
adjusted by interchanging x and y whenever the absolute value of the slope of the circle is greater
than 1.
The unequal spacing can be eliminated by using polar coordinates and is given by
X= XC +rcos𝜽
Y=Yc + rsin 𝜽
The major problem in the above two methods is the computational time. The computational
time can be reduced by considering the symmetry of circles. The shape of the circle is similar in
each quadrant. Thinking one step further shows that there are symmetry between octants too.

3 2

4
1

5
8
Computer Graphics and Multimedia

Midpoint circle algorithm:-


To simplify the function evaluation that takes place on each iteration of our circle drawing
algorithm, we can use Midpoint circle algorithm The equation of the circle can be expressed as a
function as given below
fcircle (x, y) = x2+ y2 - r2

If the point is inside the circle then f(x,y)<0 and if it is outside then f(x,y)>0 and if the point
is in the circumference of the circle then f(x,y)=[Link] the circle function is the decision parameter
in the midpoint [Link] that we have just plotted (xk,yk), we have to decide whether to
point
(xk+1, yk) or (xk+1, yk - 1) nearer to the circle.
Computer Graphics and Multimedia

Now we consider the midpoint between the points and define the decision parameter as
𝟏
Pk= fcircle (xk+1, yk+ )-----------1
𝟐
Similarly
𝟏
=( xk+1)2+( yk+ )2- r2 and
𝟐
𝟏
Pk+1= fcircle (xk+1+1, yk+1 + )------------2
𝟐

Now by subtracting the above two equations we get

Pk+1= Pk+2(xk+1)+( yk+12- yk2)-( yk+1- yk)+1

where yk+1 is either yk or yk+1 depending on the sign of pk.

Algorithm
1. Initial values:- point(0,r)
x0 = 0
y0 = r
2. Initial decision parameter
3. At each xi position, starting at i = 0, perform the following test: if pi < 0, the next point is
(xi + 1, yi) and
pi+1 = pi + 2xi+1 + 1
If pi ≥ 0, the next point is (xi+1, yi-1) and
pi+1 = pi + 2xi+1 + 1 – 2yi+1
where 2xi+1 = 2xi + 2 and 2yi+1 = 2yi – 2
4. Determine symmetry points in the other octants
5. Move pixel positions (x,y) onto the circular path centered on (xc, yc) and plot the
coordinates: x = x + xc, y = y + yc
6. Repeat 3 – 5 until x ≥ y
Computer Graphics and Multimedia

Example
r = 10

p0 = 1 – r = -9 (if r is integer round p0 = 5/4 – r to integer) Initial point (x0, y0) = (0, 10)
Computer Graphics and Multimedia

Midpoint Algorithm

ELLIPSE GENERATION ALGORITHM


Properties of ellipse

 Ellipse – A modified circle whose radius varies from a maximum value in one direction
(major axis) to a minimum value in the perpendicular direction (minor axis).

 The sum of the two distances d1 and d2, between the fixed positions F1 and F2 (called the
foci of the ellipse) to any point P on the ellipse, is the same value, i.e.
d1 + d2 = constant
 Expressing distances d1 and d2 in terms of the focal coordinates F1 = (x1, x2) and F2 = (x2,
y2),wehave:

 Cartesian coordinates:
Computer Graphics and Multimedia

 Polar coordinates:

Mid Point Ellipse Algorithm

 Symmetry between quadrants

 Not symmetric between the two octants of a quadrant

 Thus, we must calculate pixel positions along the elliptical arc through one quadrant and
then we obtain positions in the remaining 3 quadrants by symmetry

 Decision parameter:
Computer Graphics and Multimedia

 Starting at (0, ry) we take unit steps in the x direction until we reach the boundary between
region 1 and region 2. Then we take unit steps in the y direction over the remainder of the
curve in the first quadrant.

 At the boundary

 therefore, we move out of region 1 whenever

 Assuming that we have just plotted the pixels at (xi , yi).


 The next position is determined by:

If p1i < 0 the midpoint is inside the ellipse  yi is closer


If p1i ≥ 0 the midpoint is outside the ellipse  yi – 1 is closer
 At the next position [xi+1 + 1 = xi + 2]

OR

where yi+1 = yi
or yi+1 = yi – 1
 Decision parameters are incremented by:

 Use only addition and subtraction by obtaining

 At initial position (0, ry)


Computer Graphics and Multimedia

Algorithm:
1. Input rx, ry, and ellipse center (xc, yc), and obtain the first point on an ellipse centered on
the origin as
(x0, y0) = (0, ry)
2. Calculate the initial parameter in region 1 as

3. At each xi position, starting at i = 0, if p1i < 0, the next point along the ellipse centered on
(0, 0) is (xi + 1, yi) and

4. otherwise, the next point is (xi + 1, yi – 1) and

and continue until

Example
Region1
Computer Graphics and Multimedia

Region 2
(x0, y0) = (7, 3) (Last position in region 1)
Computer Graphics and Multimedia

Midpoint Ellipse Function

ATTRIBUTES OF OUTPUT PRIMITIVES


LINE ATTRIBUTES
Computer Graphics and Multimedia

The graph drawing routines may be freely mixed with those described in this section,
allowing the user to control line color, width and styles. The attributes set up by these routines
apply modally, i.e, all subsequent objects (lines, characters and symbols) plotted until the next
change in attributes are affected in the same way. The only exception to this rule is that characters
and symbols are not affected by a change in the line style, but are always drawn using a continuous
line.
1. Line type

 Solid
 Dotted – very short dash with spacing equal to or greater than dash itself
 Dashed – displayed by generating an interdash spacing
Pixel count for the span and interspan length is specified
by the mask . Ex. 111100011110001111
Note : Fixed pixel with dashes can produce unequal length dashes. It depend on line
orientation. So, need to adjust the number of plotted pixels for different slopes.

2. Line Width
 .Specify in pixels and proportion of a standard line width.
 Thicker line can be produced by.
 Adding extra pixel vertically when |m| < 1
 Adding extra pixel horizontally when |m| > 1
 Issues:
 Line have different thickness on the slope
 Problem with
 . End of the line
 . Joining the two lines (polygon)

Three possible methods to adjust the shape of the line:


Computer Graphics and Multimedia

1. Butt Cap
 To adjust the end position of the component parallel line.
2. Round Cap.
 To fill the semi circle of the each butt cap.
3. Projecting Square Cap.
 To extend the add butt cap at the specific end point.

Three possible methods to smoothly joining the line segments:


1. Miter join
 By extending the outer boundaries of each of the two lines until
they meet.
2. Round join
 To caaping the connection between two segments.
3. Bevel join
 To fill the triangular gap where the segments are m

 Pen And Brush Options


 The selected “pen” or “brush” determine the way a line will be
drawn.
 Pens and brushes have size, shape, color and pattern attribute.
Computer Graphics and Multimedia

 Pixel mask is applied in both of them.

CURVE ATTRIBUTES

A device context (DC) contains attributes that affect line and curve output. The line and
curve attributes include the current position, brush style, brush color, pen style, pen color,
transformation, and so on.

The default current position for any DC is located at the point (0,0) in logical (or world)
space. You can set these coordinates to a new position by calling the MoveToEx function and
passing a new set of coordinates.
Computer Graphics and Multimedia

Note There are two sets of line- and curve-drawing functions. The first set retains the
current position in a DC, and the second set alters the position. You can identify the functions that
alter the current position by examining the function name.

If the function name ends with the preposition "To", the function sets the current position
to the ending point of the last line drawn (LineTo, ArcTo, PolylineTo, or PolyBezierTo). If the
function name does not end with this preposition, it leaves the current position intact
(Arc,Polyline, or PolyBezier).

The default brush is a solid white brush. An application can create a new brush by calling
the CreateBrushIndirect function. After creating a brush, the application can select it into its DC
by calling the SelectObject function. Windows provides a complete set of functions to create,
select, and alter the brush in an application's DC. For more information about these functions and
about brushes in general, see Brushes.

The default pen is a cosmetic, solid black pen that is one pixel wide. An application can
create a pen by using the ExtCreatePen function. After creating a pen, your application can select
it into its DC by calling theSelectObject function. Windows provides a complete set of functions
to create, select, and alter the pen in an application's DC. For more information about these
functions and about pens in general, see Pens.

The default transformation is the unity transformation (specified by the identity matrix).
An application can specify a new transformation by calling the SetWorldTransform function.
Windows provides a complete set of functions to transform lines and curves by altering their width,
location, and general appearance. For more information about these functions, see Coordinate
Spaces and Transformations.
Computer Graphics and Multimedia

COLOR AND GREY SCALE LEVELS.

 Colors are represented by colors codes which are positive integers.


 Color information is stored in frame buffer or in separate table and use
pixel values as index to the color table.
 In raster scan systemswide range of colors

 Random scan monitorsfew color choices.


Color tables
 Each pixel can reference any one of the 256 table positions.
 Each entry in the table uses 24 bits to specify the RGB color.
 There are 17 million colors available .
 User can also set the color table entries in aPHIGS application program with the
function
SetColourRepresentation(ws, ci, colorptr)

Ws is a work station, ci as color index, colorptr points RGB color values.


Computer Graphics and Multimedia

The color lookup table with 24 bits entry accessed from a frame buffer with 8 bits per pixel.A vale
of 196 stored at a pixel position(x,y) references the location in this table containing the value of
2081.

Gray Scale
 Apply for monitor that have no color
 Shades of grey (white->light grey->dark grey->black)
 Color code mapped onto grayscale codes
 2 bits can give 4 level of grayscale
 8 bits per pixel will allow 256 combination
 Dividing the actual code with 256 will give range of 0 and 1
 Ex:
 Color code in color display is 118
 To map to nearest grayscale then
Computer Graphics and Multimedia

AREA FILL ATTRIBUTES

Many plotting programs will allow the user to draw filled polygons or symbols. The fill
specification may take two forms:

 Solid color
 Pattern fill

FILL:
In the first case we may specify a gray shade (0-255), RGB color (r/g/b all in the 0-255
range or in hexadecimal#rrggbb), HSV color (hue-saturation-value in the 0-360, 0-1, 0-1 range),
CMYK color (cyan/magenta/yellow/black, each ranging from 0-100%), or a valid color name; in
that respect it is similar to specifying the pen color settings .
There are three fill styles:

 Hollow with color border


 Filled with solid color
 Filled with specific pattern or design.
Hollow With Color Border
The basic fill style is selected in the PHIGS application program as
setInteriorStyle (fs)

where fs is normally applied to the polygon areas it can also implemented to fill region
with curved boundaries
Filled with solid color
It is used to display the single color uptoincluding the borders of the region.
Function:
SetInteriorColorIndex(Fc)
Where the fill color parameter fc is to set the desired color code.
Computer Graphics and Multimedia

Pattern Fill
Select fill pattern with
Set interior Style Index(pi)

Where the pattern index parameter pi specified to the table position.


The following are the set of statements to fill the area defined in the fill area command.
setInteriorStyle(pattern);
setInteriorStyleIndex(2);
fillarea(n,points);

The process of filling a rectangular pattern called [Link] rectangular fill pattern is
sometimes called as tiling pattern.
Soft fill
The modified boundary fill and flood fill procedures that are applied to repaint area so that
the fill color is combined with the background color is referred to as soft fill and tint fill algorithm.
Example
Using linear soft fill algorithm repaints the area that was originally painted by merging the
foreground color F with the single background color B ,where F!= B.
Computer Graphics and Multimedia

Assuming that we know the values of F and B we have to determine how these colors
originally combined with current color contents of the frame buffer.
The current RGB color P of each pixel within a area is defined as
P=tF+(1-t)B
Where T is the transperancy factor between o and 1 for each [Link] value of the T is less
than 0.5,the background color contributes more to interior color.

CHARACTER ATTRIBUTES
The appearance of displayed characters is controlled by attributes such as font,size, color,
and orientation. Attributes can be set Ooth for entire character strings(text) and for individual
characters defined as marker symbols .
There are a great many text options that can be made available to graphics programmers
.First of all, there is the choice of font (or typeface), which is a set of characters with a particular
design style such as New York, Courier, Helvetica, London, 'Times Roman, and various special
symbol groups.
The characters in a selected font can also be displayed with assorted underlining styles
(sodx,o,t.t ,e. . .d. . , d-ouble), in boldface, in italics. and in outline or shadow styles. A particular
font and associated stvle is selected in a PHlCS program by setting an integer code for the text font
parameter t f in the function.
setTextFont {tf}
Control of text color (or intensity) is managed from an application program with
SetYextColorIndex {tc}
where text color piramcter tc specifies an allowable color code.
Text size can be adjusted without changing the width-to-height ratio of characters with
setCharacterHeight {ch}
The width only of text can be set wlth the function
setCharacterExpansionFactor (cw)
Spacing between characters is controlled separately with
setCharacterSpacing (cs)
The orientation for a displayed character string is set according to the direction of the
character up vector:
setCharacterUpVector (upvect)

You might also like