0% found this document useful (0 votes)
9 views1 page

scan_line algorithm

The scan line algorithm processes polygon vertices to determine the endpoints of line segments needed for rendering. It calculates the maximum and minimum y-values from the vertices and iterates through each scan line to find active edges, determining the corresponding x-values. Finally, it draws horizontal lines between the calculated x-values for each scan line within the polygon's bounds.

Uploaded by

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

scan_line algorithm

The scan line algorithm processes polygon vertices to determine the endpoints of line segments needed for rendering. It calculates the maximum and minimum y-values from the vertices and iterates through each scan line to find active edges, determining the corresponding x-values. Finally, it draws horizontal lines between the calculated x-values for each scan line within the polygon's bounds.

Uploaded by

rn100023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Scan line algorithm

INPUT: polygon vertex as P1(X1,Y1),P2(X2,Y2),P3(X3,Y3)……

OUTPUT: endpoints of line segment to draw scan line( example: x1,x2,x3,x4,……..)

ASSUMTIONS: polygon have n vertex

Variables: Poly[][],x_values[],I,U, Z,y_scan,ymax, y_min,active_edge[][],Pnext, Ppre.

1. Get the polygon vertex as input from user as Poly[(X1,Y1),P2(X2,Y2),P3(X3,Y3)]…..


2. Find the maximum(y_max) and minimum(y_min) value of y from input vertex.
3. For each y_scan=ymax, y_scan>y_min,y_scan
{ I=0;
For each polygon
{ active edge (P1,P2) , Pnext=P2, Ppre=P5
if( y_scan ==P1.y)
{ if( ( Pnext.y>y_scan>Ppre) OR(Pnext.y<y_scan<Ppre))
{ x_values[i]=P1.x}
Else
{ x_values[i]=P1.x;
x_values[i++]=P1.x;
}
}
Else
{
U=((y_scan-P1.y)/(P2.y-P1.y));
If(0<U<1)
{ x_values[i]=P1.x+(P2.x-P1,x)*U}
}
z=0;
While(z=<i)
{ line(x_values[z],Yscan, x_values[z+1], Yscan)
z=z+2;
}
}

4 END

You might also like