written 8.3 years ago by | • modified 8.3 years ago |
Mumbai university > Comp > SEM 4 > Computer Graphics
Marks: 10M
Year: May 2014
written 8.3 years ago by | • modified 8.3 years ago |
Mumbai university > Comp > SEM 4 > Computer Graphics
Marks: 10M
Year: May 2014
written 8.3 years ago by |
Boundary fill algorithm and flood fill algorithm is defined at pixel level.
Scan line fill algorithm is defined at geometric level i.e. coordinates, edges, vertices etc.
The algorithm starts with first scan line and proceeds line by line to the last scan line.
It checks whether every pixel on that scan line satisfies inside point test or not i.e. it checks which points on that scan line are inside the polygon.
This method avoids the need for seed point.
Consider this example of convex polygon to explain this algorithm.
As shown in figure 12, algorithm begins with first scan line i.e. Ymax and proceed line by line towards the last scan line i.e. Ymin.
Here we are considering only the first and line scan and not individual edges.
For each edge of polygon we are storing 5 attributes along with the slope.
For AB we are storing:
Xmax: X2
Xmin: X1
Ymax: Y2
Ymin: Y1
Likewise we find for AD, CD and BC.
In this we have to select only those edges which are getting intersected by scan line.
For this we are using Ymax of particular edge to find out whether it is intersecting by scan line or not
Now sort the Ymax array.
So from the table we can find out that edge AB and BC are intersection of scan line.
Every time we are decreasing the scan line by 1, from Ymax to Ymin of polygon. Refer figure13
Now we have to find the corresponding X value for the intersection point.
Slope (m) = DY/DX = Change in Y / Change in X.
= Ynew – Yold / Xnew – Xold
= 1 / Xnew – Xold
Xnew – Xold = 1 / m
Therefore, Xnew = Xold + 1/m.
Like this we are finding intersecting of scan line with every edge of polygon.
Once we have found the intersecting points with both edges i.e. selected edges like AB and BC, then join these two intersecting points by solid line and continue.
Again decrease Y by 1 and find out new intersection points for those edges till one of the edges gets over i.e. the scan line goes below Ymin of one edge.
In this case edge BC gets over earlier, so discard edge BC and select next edge from sorted table, which is CD and continue the process.
The process continues till scan line reaches to Ymin of the polygon.