Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

output exits while plotting a vertical line in DDA algorithm

$
0
0
Digital Differential Algorithm
so draw a vertical line, we need co-ordinates where x is constant & only y varies
but this leads to divide by zero, & output exit's
how to overcome this??

Void DDA()
{
	int x1=100,y1=100,x2=100,y2=500,dy,dx,m,i;
	m = (y1-y2)/(x1-x2);	
	if(m<=1)
	{
		dx=1;
		dy=m*dx;	
	}
	else
	{
		dy=1;
		dx=dy/m;
	}
	for(i=x1;i<x2;i++)
	{
		x1=x1+dx;	
		y1=y1+dy;		
		putpixel(x1,y1,RED);
	}
}



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>