You are on page 1of 4

Slope consideration

And a line x=3y slope is 1/3


y= mx + c m is the slope, slope intercept form of line

Say a line x = 3y
X = x+1 (increment), compute y (approximation involved)
X = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, up 19
Y= 0, 0, 1, 1, 1, 2, 2, 2
Points = (0,0), (1,0), (2,1), (3,1), (4,1), (5,2), (6, 2), (7,2), ----- 20 points
Grid Structure
20X20

Say a line 4x = y , m=4, so slope is m > 1


Grid Structure 20X20
x= 0, 1, 2, 3, 4, 5 (increment x) and compute y
x = 0, 1, 2, 3, 4, 5,
y = 0, 4, 8, 12, 16, 20
points = (0,0), (1,4), (2,8), (3,12), (4,16), (5,20) ---- 6 points
Say a line 4x = y

Grid Structure 20X20

y = 0, 1, 2, 4, 5, 6, 7, 8, 9 so on (increment y) and Compute x


x = 0, 0, 0, 1, 1, 1, 2, 2, 9, and so on
points = (0,0), (0,1), (0,2), (1,3), (1, 4), (2, 5), (2, 6) and so on ------ 20 points
Line Equation
Two Endpoints (x1, y1), (x2, y2)

Endpoints form: (x-x1)/ (x2-x1) = (y-y1)/ (y2-y1)

Slope Intercept form: y=mx + c

Parametric form: x=x1+ (x2-x1)t, y=y1+(y2-y1)t,


t => (0 to 1)

Brute Force method:


x=1, 2, 3,…… And calculate corresponding y each time.
Say using slope intercept form
y= mx+c, m=Δy/ Δx= (y2-y1)/(x2-x1), c = y1-mx1

for -1< slope < 1, increment x by (Δx) 1 to get xi,


yi=mxi+c
take next point as (xi, round(yi).
So calculation of y involves 1 additions, 1 floating point
multiplication, 1 rounding.

yi = m xi + c
Now say
yi+1 = mxi+1+ c = m(xi+ Δx) + c = m xi + c + mΔx = yi +
mΔx

for Δx = 1, yi+1 = yi + m and xi+1 = xi + 1


take next point as ((xi+1), round(yi+1))
it calculation of y involves 1 additions, 1 rounding

for slope |m|>1, yi+1 = yi+ 1, xi+1 = xi+ 1/m


take next point as (round(xi+1), yi+1)

Digital Differential analyzer (DDA algorithm)

You might also like