# Value for dt ensure no pixels are missed implies dx 1

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: rmation Technology - Allahabad DDA Algorithm • • • • x(t ) = x1 + t ( x2 − x1 ) y (t ) = y1 + t ( y2 − y1 ) Start at t = 0 At each step, increment t by dt Choose appropriate value for dt Ensure no pixels are missed: – Implies: dx <1 dt and dx dt dy + dt xnew = xold + ynew = yold dy <1 dt • Set dt to maximum of dx and dy Indian Institute of Information Technology - Allahabad DDA Algorithm The digital differential analyzer (DDA) 0.0 < m ≤ 1.0 ⇒ ∆x = 1 ⇒ yk +1 = yk + m 1 1.0 < m ⇒ ∆y = 1 ⇒ xk +1 = xk + m Equations are based on the assumption that lines are to be processed from the left endpoint to the right endpoint. 0.0 > m ≥ −1.0 ⇒ ∆x = 1 ⇒ yk +1 = yk − m 1 − 1.0 > m ⇒ ∆y = 1 ⇒ xk +1 = xk − m Indian Institute of Information Technology - Allahabad DDA Algorithm #include 'device. h" void lineDDA (int xa, int ya, int xb, int yb) { int dx = xb - xa, dy = yb - ya, steps, k; float xIncrement, yIncrement, x = xa, y = ya; if ( abs(dx) > abs(dy) ) steps = abs (dx) ; else steps = abs (dy); xIncrement = dx / (float) steps; yIncrement = dy / (float) steps; setpixel (ROUNDlxl, ROUND(y) ) : for (k=O; k<steps; k++) { x += xIncrment; y += yIncrement; setpixel (ROUND(x), ROUND(y)); }} 1 Indian Institute of Information Technology - Allahabad DDA algorithm line(int x1, int y1, int x2, int y2) { float x,y; int dx = x2-x1, dy = y2-y1; int n = max(abs(dx),abs(dy)); float dt = n, dxdt = dx/dt, dydt = dy/dt; x = x1; y = y1; while( n-- ) { point(round(x),round(y)); x += dxdt; y += dydt; } } Indian Institute of Information Technology - Allahabad n - range of t. DDA algorithm • Still need a lot of floating point arithmetic. – 2 ‘round’s and 2 adds per pixel. • Is there a simpler way ? • Can we use only integer arithmetic ? – Easier to implement in hardware. Indian Institute of Information Technology - Allahabad Observation on lines. while( n-- ) { draw(x,y); move right; if( below line ) move up; } Indian I...
View Full Document

## This document was uploaded on 04/07/2014.

Ask a homework question - tutors are online