Академический Документы
Профессиональный Документы
Культура Документы
Chapter-2
Graphics primitives
Coordinate System:
Most graphics packages are designed to use Cartesian coordinate system. More
than one Cartesian system may be referenced by a single graphics package. Since,
different o/p device required different co-ordinate system. The coordinate referenced
by a user are called “World-coordinate system” or “User co-ordinate system”.
A Coordinate system used by a particular o/p device is called “device co-
ordinate” or “Screen co-ordinate” in the case of video monitor.
World-coordinate definition allows the user to set any convenient dimension.
Architect layout might be specified in fraction of foot, surveyor is specified in terms of
kilometer.
The world coordinate definition are given to the graphics system, it converts
these coordinate values into appropriated device coordinate system. A typical
procedure used in graphical package is to convert user coordinate definition into
normalized coordinate system and then converted to device coordinate system. This
makes the system flexible enough to accommodate the number of o/p devices. The
normalized x-y coordinate are assigned the values in the interval (0, 1). This
normalized coordinate are transferred to the device coordinate in the range (0,0) to
(xmax,ymax).
SSCW Tumkur
Computer Graphics
Point-plating Technique:
Line drawing algorithm:
Straight lines are used in computer generated pictures. They occur in
black diagrams, bar-charts and graphs, civil and mechanical engineering drawings
etc., the criteria required to generate straight lines are:
1. Lines should appear straight:
The techniques used in computers are suited to the generation of lines
which are parallel or at an angle of 45o to the x & y axis other lines crated problems.
A line segment through it starts and finishes at the required points appears as
thought they have passed through many intermediate points. In such cases it is
necessary for us to approximate the line by choosing those points which should fall on
the actual path.
2. Lines should terminate accurately: When lines are not plotted accurately, they
may terminate in the wrong place. The effect is seen as a small gap between the end
point of one line and the starting point of the next or as a cumulative error.
3. Lines should have constant density: To maintain constant density, dot should
be equally spaced. This can be achieved only in lines parallel or at 45o to the axes. In
other case, the spacing must be as even as possible; otherwise bunching of dots will
be visible.
4. Line density should be independent of line length and angle: Before plotting
a line its exact length must be determined which involves computing a square root.
Also the number of dots to be plotted in terms of distance must be calculated. This
can not be done easily. The best way is to compute an approximate line length and
use the line generation algorithm that keeps line density constant within that
estimate.
SSCW Tumkur
Computer Graphics
Algorithm: [(x1, y1) & (x2, y2) are the two end points, dx is the interval in x-axis,
dy is the interval in dy-axis, step is the number of repetition, x & y are the plotting
points and I is the loop control variable]
1. start
3. [calculate]
step dx
else
step dy
endif
plotpoint(x,y,red)
7. [loop]
for i 1 to step do
begin
x x+ xinc
y y + yinc
plotpoint(x,y,red)
end for
8. stop
SSCW Tumkur
Computer Graphics
SSCW Tumkur
Computer Graphics
DDA Bresenham’s
Xinc and yinc are calculated based on the The increment value of x and y is always
formale. unity.
There is no decision parameter There is a decision parameter used.
Both x and y values are incremented at Depending on the decision parameter the
every step. value of y is either incremented or left as
it is. However x value is incremented ata
every step.
No special cases Several cases exists, such as slope <0
and slope >0
DDA Algorithm: [ (xc, yc ) is the center of the circle, r is the radius, x and y are the
plotting points , θ is the angle of rotation’ ]
1. start
2. [Read (xc, yc ) and radius r]
3. [loop]
For θ to 360 do
Begin
a. [calculate x and y values]
X xc +r.cos θ
Y yc + r. sin θ
b. [plot point]
putpixel(x,y)
end for
4. stop
ordinate origin (xc=0, yc=0), we also calculate the points for ⅛th circle segments. Unit
step is taken in x-coordinate, starting from (xc - r) to (xc + r). The starting value for
plotting the pixel position is x=0 and y = r. The simulation at some arbitrary steps in
an algorithm is as shown in the above diagram. We assume that the position(xi, yi) as
been determined to be closer to the specified circle path. The next pixel position is
either (xi+1,yi) or (xi+1, yi-1). Before selecting the next pixel position to calculate the
first parameter as p =3-2*r
SSCW Tumkur
Computer Graphics
If p<0, then next pixel position is at (xi+1,yi) and calculate the next parameter
as p = p+2*x +1
If p>=0, then next pixel position is at (xi+1, yi+1) and calculate the next
parameter as p = p+2(x-y) +1
Repeat the above procedure until the x-coordinate is reaches to r or
x<=r.
Algorithm: [(xc, yc) is the centre of the circle, r is the radius of the circle, x and y
are the plotting points, p is the slope or constant parameter.]
1. start
2. [Read (xc ,yc) and radius r]
3. [assign]
X 0 and y r
4. [Calculate first parameter]
P 3 – 2*r
5. [Loop]
While(x<=r) do
Begin
a. [plot 8 pixels]
Plotpoint(xc + x , yc + y , 1)
Plotpoint(xc + x , yc - y , 1)
Plotpoint(xc - x , yc + y , 1)
Plotpoint(xc - x , yc - y , 1)
Plotpoint(xc + y , yc + x , 1)
Plotpoint(xc + y , yc - x , 1)
Plotpoint(xc - y , yc + x , 1)
Plotpoint(xc - y , yc - x , 1)
b. [ Check the parameter]
If p<0 then
P <- p+2*x+1
Otherwise
Y<- y -1
P <- p +2*(x-y) +1
Endif
c. [Increment x value]
X <- x+1
End while
5. stop.
SSCW Tumkur