Indian institute of information technology allahabad

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: point is (x1,y1) d start 1 1 = F ( x1 + 1, y1 + ) = a( x1 + 1) + b( y1 + ) + c 2 2 b = ax1 + by1 + c + a + 2 b = F ( x1 , y1 ) + a + 2 But (x1,y1) is a point on the line, so F(x1,y1) =0 d start = dy − dx / 2 Conventional to multiply by 2 to remove fraction ⇒ doesn’t effect sign. Indian Institute of Information Technology - Allahabad Bresenham algorithm void MidpointLine(int x1,y1,x2,y2) { int dx=x2-x1; int dy=y2-y1; int d=2*dy-dx; int increE=2*dy; int incrNE=2*(dy-dx); x=x1; y=y1; WritePixel(x,y); while (x < x2) { if (d<= 0) { d+=incrE; x++ } else { d+=incrNE; x++; y++; } WritePixel(x,y); } } Indian Institute of Information Technology - Allahabad Bresenham was not the end! 2-step algorithm by Xiaolin Wu: (see Graphics Gems 1, by Brian Wyvill) Treat line drawing as an automaton , or finite state machine, ie. looking at next two pixels of a line, easy to see that only a finite set of possibilities exist. The 2-step algorithm exploits symmetry by simultaneously drawing from both ends towards the midpoint. Indian Institute of Information Technology - Allahabad Two-step Algorithm Possible positions of next two pixels dependent on slope – current pixel in blue: Slope between 0 and ½ Slope between ½ and 1 Slope between 1 and 2 Slope greater than 2 Indian Institute of Information Technology - Allahabad Circle drawing. • Can also use Bresenham to draw circles. • Use 8-fold symmetry E M SE Previous Pixel Choices for Current pixel Indian Institute of Information Technology - Allahabad Choices for Next pixel Circle drawing. • Implicit form for a circle is: f ( x, y ) = ( x − xc ) 2 + ( y − yc ) 2 − r 2 If SE is chosen d new = d old + (2 x p − 2 y p + 5) If E is chosen d new = d old + (2 x p + 3) • Functions are linear equations in terms of (xp,yp) –Termed point of evaluation Indian Institute of Information Technology - Allahabad Problems with Bresenham algorithm • Pixels are drawn as a single line ⇒ unequal line intensity with change in angle. Pixel density = √2.n pixels/mm Can draw lines in darker colours according to line direction. - Better solution : antialiasing ! Pixel density = n pixels/mm Indian Institute of Information Technology - Allahabad Summary of line drawing so far. • Explicit form of line – Inefficient, difficult to control. • Parametric form of line. – Express line in terms of parameter t – DDA algorithm • Implicit form of line – Only need to test for ‘side’ of line. – Bresenham algorithm. – Can also draw circles. Indian Institute of Information Technology - Allahabad Indian Institute of Information Technology - Allahabad Summary of aliasing. • • • • • Sampling theory tells us aliasing is caused by frequencies being present above the Nyquist limit. Ideal solution : band-pass filter to remove high frequencies. Fourier transform tells us the transform of a band-pass filter is a sinc function. Convolution theory tells us we can convolve with a sinc function in the spatial domain instead. A sinc function is an impractical filter. Indian Institute of Information Technology - Allahabad...
View Full Document

This document was uploaded on 04/07/2014.

Ask a homework question - tutors are online