Flood Fill Algorithm:: Disadvantage
Flood Fill Algorithm:: Disadvantage
In fill algorithm, we start from a specified interior point (x, y) and reassign
all pixel values are currently set to a given interior color with the desired
color. Using either a 4-connected or 8-connected approaches, we then
step through pixel positions until all interior points have been repainted.
Disadvantage:
1. Very slow algorithm
2. May be fail for large polygons
3. Initial pixel required more knowledge about surrounding pixels.
Algorithm:
1. Procedure floodfill (x, y,fill_ color, old_color: integer)
2. If (getpixel (x, y)=old_color)
3. {
4. setpixel (x, y, fill_color);
5. fill (x+1, y, fill_color, old_color);
6. fill (x-1, y, fill_color, old_color);
7. fill (x, y+1, fill_color, old_color);
8. fill (x, y-1, fill_color, old_color);
9. }
10. }
1
Boundary Filled Algorithm:
This algorithm uses the recursive method. First of all, a starting pixel
called as the seed is considered. The algorithm checks boundary pixel or
adjacent pixels are colored or not. If the adjacent pixel is already filled or
colored then leave it, otherwise fill it. The filling is done using four
connected or eight connected approaches.
Boundary can be checked by seeing pixels from left and right first. Then
pixels are checked by seeing pixels from top to bottom. The algorithm
takes time and memory because some recursive calls are needed.
2
So check all pixels color before applying the algorithm.
Algorithm:
In Computer graphics,
3
Transformation Techniques-
In Computer graphics,
2D Translation is a process of moving an object from one position to another in a two dimensional
plane.
Consider a point object O has to be moved from one position to another in a 2D plane.
Let-
Initial coordinates of the object O = (Xold, Yold)
New coordinates of the object O after translation = (Xnew, Ynew)
Translation vector or Shift vector = (Tx, Ty)
4
This translation is achieved by adding the translation coordinates to the old coordinates of
the object as-
Xnew = Xold + Tx (This denotes translation towards X axis)
Ynew = Yold + Ty (This denotes translation towards Y axis)
5
Problem-01:
Given a circle C with radius 10 and center coordinates (1, 4). Apply the translation with
distance 5 towards X axis and 1 towards Y axis. Obtain the new coordinates of C without
changing its radius.
Solution-
Given-
Old center coordinates of C = (Xold, Yold) = (1, 4)
Translation vector = (Tx, Ty) = (5, 1)
Alternatively,
In matrix form, the new center coordinates of C after translation may be obtained as-
6
Problem-02:
Given a square with coordinate points A(0, 3), B(3, 3), C(3, 0), D(0, 0). Apply the translation
with distance 1 towards X axis and 1 towards Y axis. Obtain the new coordinates of the
square.
Solution-
Given-
Old coordinates of the square = A (0, 3), B(3, 3), C(3, 0), D(0, 0)
Translation vector = (Tx, Ty) = (1, 1)
7
Xnew = Xold + Tx = 3 + 1 = 4
Ynew = Yold + Ty = 3 + 1 = 4
8
To gain better understanding about 2D Translation in Computer Graphics,
It consists of two axes: major and minor axes where the major axis is the
longest diameter and minor axis is the shortest diameter.
Unlike circle, the ellipse has four-way symmetry property which means
that only the quadrants are symmetric while the octants are not.
9
Here, we will calculate the points for one quadrant while the points for the
remaining three can be calculated using the former points.
The region R1 has the value of slope as m<-1 while R2 has the value of
slope as m > -1.
The starting point for R1 will be (0, ry) and for R2, the initial points will
become the ending points of R1, where the slope becomes greater than -
1. Thats why we need to keep in check the value of slope while plotting
the points for R1 to know whether we have reached R2 or not.
10
Advantages:
Disadvantages:
11