1
00:01:02,550 --> 00:01:08,650
We will be having the first of a series of
lectures on raster graphics. In raster graphics
2
00:01:08,650 --> 00:01:15,390
we will essentially be taking of display on
raster refresh displays. In the last lecture
3
00:01:15,390 --> 00:01:22,390
I had briefly described what are raster refresh
displays or raster refresh terminals or raster
4
00:01:23,140 --> 00:01:26,780
refresh type of CRT's.
5
00:01:26,780 --> 00:01:33,780
Now in the first display method that we will
be talking of is called a DDA or it stands
6
00:01:34,979 --> 00:01:41,979
for digital
differential analyzer. The basic idea in this
method of drawing lines is that if you have
7
00:02:00,200 --> 00:02:07,200
to draw a line from a point x1 y1 to a point
x2 y2, we can easily compute the slope of
8
00:02:11,790 --> 00:02:18,790
this line which is delta y by delta x. Therefore
if we know that the particular pixel, this
9
00:02:22,620 --> 00:02:29,620
particular pixel is a pixel x y if this pixel
has already been displayed then the next pixel
10
00:02:30,349 --> 00:02:37,349
to be displayed should be a pixel given by
x plus delta x and y plus delta y or some
11
00:02:41,599 --> 00:02:48,230
amount proportional to delta x. So what we
will normally say, it should be epsilon times
12
00:02:48,230 --> 00:02:52,780
delta x and epsilon times delta y.
13
00:02:52,780 --> 00:02:59,780
So if we start from the first pixel here that
pixel will is let's say the pixel x y then
14
00:03:01,330 --> 00:03:05,670
we will display the pixel which will be given
by x plus epsilon times delta x and y plus
15
00:03:05,670 --> 00:03:12,670
epsilon times delta y. As long as we keep
incrementing in proportion to the, we keep
16
00:03:13,330 --> 00:03:19,340
incrementing x and y by amounts proportional
to delta x and delta y, we will always get
17
00:03:19,340 --> 00:03:26,340
a line which will be in this direction, so
that's the basic idea in this.
18
00:03:32,650 --> 00:03:39,650
But the problem that comes is let's say this
is one pixel, we just a make a small grid.
19
00:03:46,260 --> 00:03:53,260
If the first pixel that has been displayed
is this one, so this is my x y. Now I increment
20
00:04:00,620 --> 00:04:07,620
x and y, x will become epsilon times delta
x plus x and y will become epsilon times delta
21
00:04:10,290 --> 00:04:17,290
y plus y. If I take my epsilon to be very
small then this amount will still be the same
22
00:04:20,479 --> 00:04:27,479
as x because x and y are bound to be integers.
So let's say x is let's say 100 and y is let's
23
00:04:32,930 --> 00:04:39,930
say 50 and I take epsilon times delta x to
be very small let's say 0.001 and I take epsilon
24
00:04:45,319 --> 00:04:52,319
times delta y to be let's say 0.002. Even
though I will increment x and y by these amounts,
25
00:04:55,470 --> 00:05:02,470
I will still be displaying the same pixel
because 100 plus 0.001 will mean that x will
26
00:05:03,389 --> 00:05:10,389
get rounded off to 100 again. So I will end
up displaying the same pixel again. So I will
27
00:05:10,410 --> 00:05:17,410
keep on displaying the same pixel till I am
able to increment x by 1 or y by 1. So this
28
00:05:19,949 --> 00:05:26,949
amount epsilon times delta x and epsilon times
delta y, these amounts have to be chosen very
29
00:05:28,759 --> 00:05:29,759
carefully.
30
00:05:29,759 --> 00:05:35,240
If they are very small then we will end up
displaying the same pixel and again and again
31
00:05:35,240 --> 00:05:41,860
and we will be doing wasteful computation.
The algorithm will become unnecessarily slow.
32
00:05:41,860 --> 00:05:48,210
If I take epsilon delta x or epsilon delta
y to be very big then maybe my line will not
33
00:05:48,210 --> 00:05:55,210
be continuous. If I take epsilon delta x to
be 1 and epsilon delta y to be 2, I am displaying
34
00:05:59,159 --> 00:06:06,159
this pixel and the next pixel to be displayed
will be this one. Similarly the next one to
35
00:06:06,839 --> 00:06:13,839
be displayed would be this pixel, this line
will not look continuous.
36
00:06:18,300 --> 00:06:23,469
So the important question is how do we chose
the value of epsilon delta x and epsilon delta
37
00:06:23,469 --> 00:06:30,469
y. The choice of epsilon will govern the quality
of the algorithm whether we are able to draw
38
00:06:36,270 --> 00:06:43,270
good lines or not that depends purely on the
choice of epsilon. So we have two algorithms,
39
00:06:45,059 --> 00:06:52,059
one is called the simple DDA. Again DDA stands
for digital differential analyzer and the
40
00:06:54,629 --> 00:07:01,629
other is called the symmetric DDA. The only
difference between these two algorithms is
41
00:07:07,919 --> 00:07:14,919
the choice of epsilon. We will just go through
both these algorithms and see how they will
42
00:07:19,909 --> 00:07:26,909
compare and what kind of results they come
up with.
43
00:07:31,469 --> 00:07:38,469
We will start with the symmetric DDA
and we will write this algorithm for drawing
a line from a point x1 y1 to a point x2 y2.
44
00:07:58,159 --> 00:08:05,159
The first step would be to compute this delta
x and delta y. So let's say we will call this
45
00:08:08,770 --> 00:08:15,770
delta x as x increment and that will be equal
to x2 minus x1, we will say y increment will
46
00:08:20,180 --> 00:08:27,180
be equal to y2 minus y1. Then the way we compute
this epsilon delta x and epsilon delta y would
47
00:08:36,659 --> 00:08:43,659
be that lets say if I take this x increment
and y increment and I keep dividing them by
48
00:08:47,589 --> 00:08:54,589
2. I say x increment is initially 50, y increment
is 100. I keep dividing them by 2, 50 will
49
00:08:58,210 --> 00:09:05,210
become 25, 100 will become 50, this will become
12.5, this will become 25, this will become
50
00:09:07,630 --> 00:09:14,630
6.25, this will become 12.5 then 3.125, 6.25,
this will become 1.5625 and this will be 3.5
51
00:09:19,480 --> 00:09:26,480
and this will finally become 0.78 something
and this
will become 1.5625.
52
00:09:34,260 --> 00:09:41,260
We will keep dividing both of them by 2, till
one of them becomes less than 1. The idea
53
00:09:45,339 --> 00:09:52,339
is if you saw what was happening here, if
this value of epsilon times delta x becomes
54
00:09:53,800 --> 00:09:58,519
very small then we are doing wasteful computation,
if it is very large we are not displaying
55
00:09:58,519 --> 00:10:05,519
the pixels correctly. So this value epsilon
delta x or epsilon delta y, at least one of
56
00:10:07,000 --> 00:10:13,009
them has to be less than one. If both of them
are greater than one, we will end up missing
57
00:10:13,009 --> 00:10:20,009
some pixels, so at least one of them should
be less than one. At the same time it should
58
00:10:20,180 --> 00:10:24,649
not be very much less than one, if it is very
much less than one then again we will be doing
59
00:10:24,649 --> 00:10:31,649
a lot of wasteful computation because if any
of them is less than half let's say then the
60
00:10:32,829 --> 00:10:38,329
same pixel will be displayed again and again.
61
00:10:38,329 --> 00:10:45,329
So therefore what we do is we will take x
increment y increment, keep dividing both
62
00:10:49,100 --> 00:10:56,100
of them by two till at least one of them is
less than one. So we will write a piece of
63
00:11:01,819 --> 00:11:08,819
code for that; while... you are all familiar
with the Pascal... so I am writing in a somewhat
64
00:11:35,259 --> 00:11:42,259
Pascal like syntax. So essentially what we
are doing is in this while loop, while either
65
00:12:26,970 --> 00:12:33,970
absolute value of x increment or absolute
value of y increment is greater than one.
66
00:12:34,449 --> 00:12:39,889
If any one of them are greater than one we
will divide both of them by 2 and we will
67
00:12:39,889 --> 00:12:45,180
keep repeating this process till both of them
become less than or equal to one. I think
68
00:12:45,180 --> 00:12:52,180
I said it wrong earlier. again either of them
while either of them is greater than one I
69
00:12:56,550 --> 00:13:03,550
will keep dividing, so till both of them become
less than one, I will keep dividing.
70
00:13:06,689 --> 00:13:13,689
At this point x increment is 0.78 and y increment
is 1.5625. This condition is still satisfied,
71
00:13:19,579 --> 00:13:23,370
absolute value of x increment is greater than
1 or absolute value of y increment is greater
72
00:13:23,370 --> 00:13:29,860
than 1. So I will again carryout this loop
which means this will become 0.39 and this
73
00:13:29,860 --> 00:13:36,860
will become 0.78. So I keep dividing till
both of them become less than 1. I think I
74
00:13:38,379 --> 00:13:45,379
said it wrong earlier. Till both of them become
less than one. And the first time I find that
75
00:13:51,399 --> 00:13:58,399
both of them are less than one, I will come
out of this while loop. Is that all right?
76
00:14:01,949 --> 00:14:08,949
So at the end of this loop, at the end of
this while loop my x increment and y increment
77
00:14:11,040 --> 00:14:18,040
both these variables will have values less
than or equal to 1.
78
00:14:19,990 --> 00:14:26,990
In fact not equal to one, so I put an equal
to here that both of them will be less than
79
00:14:27,689 --> 00:14:34,689
one. And in terms of what I have written earlier
epsilon delta x and epsilon delta y, my x
80
00:14:42,529 --> 00:14:49,529
increment is nothing but epsilon times delta
x and the variable y increment is nothing
81
00:14:51,649 --> 00:14:58,649
but epsilon times delta y. Now in this both
x increment and y increment have to be declared
82
00:15:06,850 --> 00:15:13,850
as real numbers, they cannot be integers.
If they are integers then when I am dividing,
83
00:15:16,209 --> 00:15:23,209
I divide 25 by 2, it will not be 12.5. It
will get truncated and maybe it will be 12
84
00:15:26,329 --> 00:15:31,899
because of that there will be an error and
the slope of the line will not be correct.
85
00:15:31,899 --> 00:15:38,899
So both x increment excuse me and y increment
have to be declared as real numbers. Now after
86
00:15:43,389 --> 00:15:48,600
this stage we have the values of x increment
and y increment. Now we can start the display
87
00:15:48,600 --> 00:15:50,069
part of it.
88
00:15:50,069 --> 00:15:57,069
So what we will do is we will say x
will be initialized to x1. What we are doing
now is this is our screen, this is our starting
89
00:16:11,249 --> 00:16:18,249
point, this is the end point. The starting
point is x1 y1, the ending point is x2 y2.
90
00:16:22,600 --> 00:16:29,290
So the variables x y would be the variables
of the current displayed pixel or the variables
91
00:16:29,290 --> 00:16:36,290
corresponding to the current displayed pixel.
So the first pixel will display will be the
92
00:16:36,290 --> 00:16:43,029
pixel x1 y1 and the second pixel will display
will be x1 y1 incremented by x increment and
93
00:16:43,029 --> 00:16:49,889
y increment, so there should be some increment
in this direction and so on. So we will initialize
94
00:16:49,889 --> 00:16:56,889
x to be equal to x1 and y to be equal to y1.
Now I said x equal to x1 but I will come back
95
00:17:03,220 --> 00:17:10,220
to it, for certain reasons we will be actually
putting it equal to plus 0.5, both of them.
96
00:17:11,620 --> 00:17:18,620
I will come back to it, why do we put a plus
0.5, when we write down the full algorithm
97
00:17:19,300 --> 00:17:26,300
then I will explain why we are adding a 0.5
here. Then I have put x y equal to this pixel,
98
00:17:32,730 --> 00:17:39,730
I have to keep displaying till I reach my
last pixel. So we say while x is less than
99
00:17:40,130 --> 00:17:47,130
x2 do begin. While x is less than x2 we are
doing this, these three statements are being
100
00:18:34,960 --> 00:18:41,960
repeated in a loop. The first is plot truncate
of x and truncate of y.
101
00:18:44,850 --> 00:18:51,850
Let's say I have to draw a line from a point
150 to a point 200, 100. So initially my x
102
00:18:55,410 --> 00:19:02,410
increment is equal to 100 and y increment
is equal to 50, I will keep dividing by 2.
103
00:19:04,680 --> 00:19:11,680
So finally I will get this to be probably
0.39 and this would come out to be 0.78. I
104
00:19:19,800 --> 00:19:26,800
am initializing x to be x1 plus 0.5, for the
time being let's take it to be x1, so my x
105
00:19:29,290 --> 00:19:36,290
is 100 and y is 50. First time I will plot
x y, so pixel number 100, 50 will get displayed.
106
00:19:44,880 --> 00:19:50,740
Second time x will get incremented by 0.78,
so it will become 100 plus 0.78 which is equal
107
00:19:50,740 --> 00:19:57,740
to 100.78 and y will become 50.39 but now
this screen is an array of pixels. In an array
108
00:20:04,810 --> 00:20:11,560
I can only address integer locations. So instead
of 100.78, I have to address pixel number
109
00:20:11,560 --> 00:20:18,560
101. I will round it off and instead of 50.39,
I will address pixel number 50. So the pixel
110
00:20:21,430 --> 00:20:26,110
to be displayed after the pixel number 100,
50 will be the pixel 101, 50. Is that understood?
111
00:20:26,110 --> 00:20:33,110
If the pixel to be displayed is 101, 50 that
is this is 100, 50; 101, 50 will be this pixel.
112
00:20:47,380 --> 00:20:54,380
Now instead of rounding off if you notice
I have put truncation over here. If I am truncating
113
00:20:55,260 --> 00:21:02,260
100.78 will actually become 100 but instead
of x1 I have put x1 plus 0.5. So initially
114
00:21:04,430 --> 00:21:11,430
my pixel 100, 50 so x y became 100.5 and y
became 50.5. In the first cycle I truncated
115
00:21:19,130 --> 00:21:26,130
both these numbers and displayed 100 and 50,
displayed the pixel number numbered as 100,
116
00:21:26,480 --> 00:21:33,480
50. In my second time when I come here my
x will be 100, I will write here again, x
117
00:21:35,500 --> 00:21:42,500
will be 100.5 plus 0.78 and y will be 50.5
plus 0.39. Sir why did you save the, if we
118
00:21:48,510 --> 00:21:55,510
use the command round off without initializing
the value of x and y by increasing 0.5. That's
119
00:21:58,090 --> 00:22:03,590
right if we do not put this 0.5 here then
we will replace truncation by rounding off.
120
00:22:03,590 --> 00:22:04,090
The same thing.
121
00:22:04,090 --> 00:22:09,810
It will be the same thing but since we are
putting 0.5 here, we are putting truncation
122
00:22:09,810 --> 00:22:16,810
instead of rounding off. That is that's you
have come to. Now x will become 101.28 and
123
00:22:22,790 --> 00:22:29,790
this will become 50.89. Now when I truncate
these two I will still get 101, 50 which is
124
00:22:35,620 --> 00:22:42,620
this. Now the result of adding 0.5 here and
then truncating is the same as if I don't
125
00:22:44,000 --> 00:22:51,000
add 0.5 here and do a rounding off. Is that
appreciated?
126
00:22:56,970 --> 00:23:03,970
In general if you take any number x, round
off x would be the same as truncation of x
127
00:23:14,260 --> 00:23:21,260
plus 0.5. This you can check up for any number.
That is why here we are adding 0.5 in the
128
00:23:26,870 --> 00:23:33,870
beginning and then truncating every time and
the reason we prefer to do this is truncation
129
00:23:36,050 --> 00:23:43,050
is much faster than rounding off. Truncation
takes much more time sorry the other way round.
130
00:23:44,180 --> 00:23:51,180
Rounding off is very slow and truncation is
faster. So we prefer to truncate rather than
131
00:23:53,510 --> 00:24:00,510
rounding it out. Sir but this is the only
thing for the first two pixel, the rounding
132
00:24:04,160 --> 00:24:11,160
off and truncation will mean coincide. No,
but for the rest afterwards then they will.
133
00:24:14,420 --> 00:24:21,420
For all of them it will coincide. No, for
example you take first point that maybe different.
134
00:24:22,230 --> 00:24:23,970
No let's just just a sec.
135
00:24:23,970 --> 00:24:30,970
In one case we will start with 100, 50, we
are starting with 100, 50 this will become
136
00:24:34,900 --> 00:24:41,900
100.78, 50.39. Then the next time it will
become, you add 0.78 again 101.56, this will
137
00:24:47,540 --> 00:24:54,540
become 50.78. Then it will become, we will
add 0.78 again so this will become 102.34.
138
00:24:56,110 --> 00:25:03,110
Is that right? And this will become 51.17
and so on. In this case we are supposed to
139
00:25:10,990 --> 00:25:17,990
round off. So this one becomes 101, this will
become 50, this will be 102, this will be
140
00:25:19,900 --> 00:25:26,900
51, this will still be 102 and this will be
51. Is that okay? Now I have added 0.5 in
141
00:25:29,520 --> 00:25:36,520
the beginning itself, so this becomes 100.5
and 50.5, this will be 101.28 and 50.89. This
142
00:25:40,970 --> 00:25:47,970
one will be 102.06 and this will be 51.28.
This will be 102.84 and this will be 51.67.
143
00:26:01,860 --> 00:26:08,860
Now when I truncate this will become 101,
this will become 50, this will become 102,
144
00:26:11,050 --> 00:26:18,050
this will be 51. This will become 102 and
this will be 51. The results are the same.
145
00:26:20,660 --> 00:26:27,460
See basically when I have added 0.5 in the
beginning that 0.5 is carried over in all
146
00:26:27,460 --> 00:26:34,460
the iterations. All these numbers will be
0.5 higher than these numbers. I have added
147
00:26:35,020 --> 00:26:40,660
0.5 only in the beginning but that effect
will remain in all the iterations, in all
148
00:26:40,660 --> 00:26:47,510
the cycles let's say. So initially this number
is 0.5 higher than this. This is also 0.5
149
00:26:47,510 --> 00:26:54,510
higher than this, this is also 0.5 higher
than this. So this effect will go on in all
150
00:26:55,850 --> 00:27:01,170
the iterations. As a result if I take any
of these numbers, the result of truncating
151
00:27:01,170 --> 00:27:08,170
them will be same as what I will get from
there. Is that okay?
152
00:27:12,020 --> 00:27:19,020
So coming back to this algorithm, what we
have done is we started with the pixel x y
153
00:27:22,150 --> 00:27:29,150
and we have displayed pixels in the direction
of the slope by adding x increment and y increment
154
00:27:30,870 --> 00:27:36,330
every time and instead of rounding it off,
we have added 0.5 in the beginning and then
155
00:27:36,330 --> 00:27:43,330
we are truncating it every time. And however
we have found out x increment and y increment.
156
00:27:44,820 --> 00:27:51,820
We took delta x that is x2 minus x1 and delta
y which is y2 minus y1 and kept on dividing
157
00:27:51,820 --> 00:27:58,820
them by 2 till both of them were less than
one. So this is referred to as a symmetric
158
00:28:01,690 --> 00:28:08,690
DDA algorithm or symmetric digital differential
analyzer. Any question on this symmetric DDA
159
00:28:12,370 --> 00:28:14,810
algorithm?
160
00:28:14,810 --> 00:28:21,810
Now we will see the algorithm which is referred
to as a simple DDA. If we have to draw a line
161
00:28:38,330 --> 00:28:45,330
from this point to this point, in the symmetric
DDA what we did was we took increments in
162
00:28:50,030 --> 00:28:57,030
the x direction and y direction depending
on the multiples of two that means we had
163
00:29:02,070 --> 00:29:09,070
taken delta x and delta y. Essentially what
we did was we took the higher of the two,
164
00:29:09,310 --> 00:29:16,310
let's say if the higher of the two is 50,
we found out some number 2 to the power n
165
00:29:16,420 --> 00:29:21,740
which is bigger than 50. Some multiple of
2 which is bigger than 50 and we divided both
166
00:29:21,740 --> 00:29:28,740
of them by that because you are dividing both
delta x and delta y by 2 every time. So if
167
00:29:31,080 --> 00:29:38,080
you are taking 50, so 2 to the power 6 is
equal to 64.
168
00:29:42,220 --> 00:29:46,260
So we are dividing this by 64 and delta x
let's say if it is 25, we are dividing that
169
00:29:46,260 --> 00:29:53,260
also by 64. So this delta x and this delta
y are both being divided by 2 to the power
170
00:30:00,060 --> 00:30:05,710
n. In a simple DDA instead of dividing it
by 2 to the power n, we will divide it by
171
00:30:05,710 --> 00:30:12,710
higher of delta x or delta y. So that out
of delta x and delta y at least one of them
172
00:30:17,090 --> 00:30:24,090
should be equal to one, between delta x and
delta y if let's say one is 25, the other
173
00:30:27,070 --> 00:30:34,070
is 50, we will divide both of them by 50.
You are not clear? My total increment in the
174
00:30:42,020 --> 00:30:49,020
x direction let's say is 25, my total increment
in the y direction let's say is 50. Instead
175
00:30:49,210 --> 00:30:56,210
of dividing it by 64, now we will divide it
by 50. So that the increment that I will take
176
00:31:00,870 --> 00:31:06,560
in the x direction will be 25 by 50 or 0.5
and the increment that I will take in the
177
00:31:06,560 --> 00:31:12,440
y direction will be 50 by 50 or 1.0.
178
00:31:12,440 --> 00:31:18,930
As a result either delta x or delta y will
always be equal to one, one of the two will
179
00:31:18,930 --> 00:31:25,930
always be one. In the symmetric DDA case both
of them are certainly less than one. In this
180
00:31:30,140 --> 00:31:37,140
case one of them has to be equal to one. The
basic reason behind doing this is that if
181
00:31:43,830 --> 00:31:50,220
my increment in both the direction is less
than one then it is possible that I will end
182
00:31:50,220 --> 00:31:57,220
up displaying the same pixel again. While
if one of them at least is equal to one then
183
00:31:59,250 --> 00:32:03,620
that will not happen because in one direction
at least, I am incrementing by an amount equal
184
00:32:03,620 --> 00:32:05,460
to one.
185
00:32:05,460 --> 00:32:12,460
Of course in symmetric DDA also we will never
end up displaying the same pixel again. that
186
00:32:14,100 --> 00:32:19,850
will not happen in the symmetric DDA either.
Somebody said something? That was happening
187
00:32:19,850 --> 00:32:26,850
sir. Again. That was happening in the last
example, in the last three points that you
188
00:32:26,980 --> 00:32:33,980
have taken the last two.
189
00:32:34,310 --> 00:32:40,890
So these two points were being the same, you
are right. In the symmetric DDA these two
190
00:32:40,890 --> 00:32:45,890
points can be the same because the increment
was less than one but if my increment is more
191
00:32:45,890 --> 00:32:51,130
than one, at least one of the two increments
is more is equal to one then the same point
192
00:32:51,130 --> 00:32:58,070
will never get displayed again because at
least one of the pixels will shift. The next
193
00:32:58,070 --> 00:33:03,240
pixel to be displayed either in the x direction
or in the y direction, it will be incremented
194
00:33:03,240 --> 00:33:06,900
by one.
195
00:33:06,900 --> 00:33:13,900
So in this case if my delta y is equal to
1, in that case every time I will take a pixel
196
00:33:14,100 --> 00:33:20,740
in the new row. Every time I am increasing
delta y by 1, delta x may or may not increase
197
00:33:20,740 --> 00:33:27,740
but delta y will definitely increase that
is a simple DDA. So we will just write down
198
00:33:35,480 --> 00:33:42,480
the algorithm for this and see how it compares.
If you look at the symmetric DDA, this is
199
00:33:47,270 --> 00:33:54,270
the algorithm we had written. Now in contrast
to this we will retain these two steps and
200
00:33:55,760 --> 00:34:02,760
this part will now change. In fact these will
also not be required.
201
00:34:06,480 --> 00:34:13,480
What we will do is simple DDA. We will take
a variable let's say length which will be
202
00:34:21,030 --> 00:34:28,030
to start with let's say absolute value of
x2 minus x1. Then we will say if absolute
203
00:34:35,220 --> 00:34:42,220
value of y2 minus y1 is greater than length,
then length will be equal to absolute value
204
00:34:55,030 --> 00:35:02,030
of y2 minus y1. Essentially between x2 minus
x1 and y2 minus y1 whichever is greater in
205
00:35:08,710 --> 00:35:15,710
magnitude that we are assigning equal to length
and then we will say x increment will be equal
206
00:35:18,140 --> 00:35:25,140
to x2 minus x1 divided by length and y increment
will be equal to y2 minus y1 divided by length.
207
00:35:41,730 --> 00:35:47,710
Is that okay?
208
00:35:47,710 --> 00:35:54,710
Once you have calculated x increment and y
increment then the rest of the algorithm will
209
00:35:57,840 --> 00:36:03,860
remain the same. Basically this loop for displaying
the line is still the same. We have already
210
00:36:03,860 --> 00:36:09,170
found out what is the value of x increment
and y increment, we know the starting point,
211
00:36:09,170 --> 00:36:16,170
we repeated in the same loop and we will able
to draw the complete line.
212
00:36:19,020 --> 00:36:26,020
The difference between these two algorithms,
the first difference is essentially the value
213
00:36:38,310 --> 00:36:45,310
of epsilon delta x. In symmetric DDA both
epsilon delta x and epsilon delta y are less
214
00:36:48,490 --> 00:36:55,490
than one. In a simple DDA either epsilon delta
x or epsilon delta y will be equal to one.
215
00:36:59,190 --> 00:37:06,190
One of them will always be equal to one, this
is in the case of simple. As a result in a
216
00:37:13,330 --> 00:37:20,330
simple DDA there will be no repetition of
points or repetition of pixels, the same pixel
217
00:37:30,740 --> 00:37:37,740
will not be displayed again. In fact I will
just show you some lines drawn by the two
218
00:37:41,750 --> 00:37:48,750
algorithms. Are you able to see it? This figure,
can you see it clearly? This is the line drawn
219
00:38:15,290 --> 00:38:22,290
by a symmetrical DDA. In contrast to this,
a line draw by the simple DDA will look something
220
00:38:22,520 --> 00:38:29,520
like this. Is it visible? I hope so.
221
00:38:36,400 --> 00:38:43,400
If you notice the difference between the two
yes, the number of point in simple are less.
222
00:39:28,150 --> 00:39:35,150
The blue circle that I have made, those are
the lines or the pixels selected under the
223
00:39:35,380 --> 00:39:42,380
symmetric DDA. The black crosses are the one
selected under the simple DDA. These pixels
224
00:39:43,570 --> 00:39:50,570
are extra in the case of symmetric DDA. So
the symmetric DDA draws more pixels than the
225
00:39:54,300 --> 00:40:01,300
simple DDA, the simple DDA always draws less
number of pixels and the reason is let's say
226
00:40:07,670 --> 00:40:14,670
if delta x is less than delta y that means
the line is traveling more in the y direction.
227
00:40:15,540 --> 00:40:19,740
If the line is traveling more in the y direction
then in the y direction, you are at least
228
00:40:19,740 --> 00:40:26,740
incrementing by one pixel every time. So in
the y direction you will always be moving
229
00:40:28,750 --> 00:40:35,750
by one pixel. So in every iteration, you are
going to a different row of pixels that need
230
00:40:38,450 --> 00:40:40,910
not be the case in symmetric DDA.
231
00:40:40,910 --> 00:40:47,910
In the y direction also your increment will
be less than one. So on the same line, you
232
00:40:49,940 --> 00:40:55,990
will end up drawing sometimes two pixels before
going on to the next line and that is what
233
00:40:55,990 --> 00:41:02,990
is happening in this case. Here in the x direction,
the slope is more. The movement is more in
234
00:41:04,490 --> 00:41:11,490
the x direction. So in the simple DDA every
time you move in the x direction, every time
235
00:41:16,920 --> 00:41:21,220
you draw a new pixel you will at least move
in the x direction by one. So that is why
236
00:41:21,220 --> 00:41:27,890
you can in see the black crosses and you go
from one pixel to a second pixel, you are
237
00:41:27,890 --> 00:41:33,360
always moving in the x direction at least
by one pixel while that is not true in the
238
00:41:33,360 --> 00:41:40,360
case of the symmetric DDA. This is one pixel
drawn, the next pixel drawn is here. So in
239
00:41:41,830 --> 00:41:48,830
the x direction you have not moved at all.
Similarly here one pixel was drawn and the
240
00:41:49,260 --> 00:41:56,260
next pixel drawn is this one. Why this choice
of 2 to the power of 64. Sir or powers of
241
00:41:57,410 --> 00:42:04,410
2, why don't we have just 1.5 times the length.
That's a good question.
242
00:42:13,369 --> 00:42:20,369
Essentially what he has asked is let's say
delta x is 25 and delta y is 50. We kept on
243
00:42:20,840 --> 00:42:27,660
dividing by 2 in every iteration till both
the numbers became less than one. Why divide
244
00:42:27,660 --> 00:42:34,660
it by 2? Anyone trying to make a guess on
that, why should you divide by two every time?
245
00:42:37,300 --> 00:42:44,300
What I am saying is that instead of why divide
2, like two is obvious because like left shifting
246
00:42:47,400 --> 00:42:53,070
it will give a faster computation. But using
the same algorithm... if found the length
247
00:42:53,070 --> 00:42:58,860
we just multiply the length by 1.5; I will
say that divide by that will be a first this
248
00:42:58,860 --> 00:43:04,970
because this is in a loop that one won't be
in a loop. I will explain both the points.
249
00:43:04,970 --> 00:43:11,960
See the first reason, the first part of the
question is why we are dividing by two every
250
00:43:11,960 --> 00:43:17,020
time and the reason is given himself that
is division by 2 is simpler than division
251
00:43:17,020 --> 00:43:24,020
by any other number. We are trying to divide
any number by 2, let's say the number is you
252
00:43:25,800 --> 00:43:31,090
want to divide it by 2. All that you have
to do is a right shift. If you want to multiply
253
00:43:31,090 --> 00:43:38,090
it by 2, all that you do is a left shift.
That means if you want to divide this by 2
254
00:43:38,800 --> 00:43:45,800
let's say if this is your number, this will
just become something like this, this is this
255
00:43:47,700 --> 00:43:54,700
number divided by 2. If you want to multiply
this number by 2, all that you will do is
256
00:43:54,720 --> 00:44:01,720
a left shift and this number will become like
this. So division by two is much easier to
257
00:44:04,740 --> 00:44:10,750
implement than division by any other number.
Therefore we choose a multiple of two and
258
00:44:10,750 --> 00:44:17,750
we keep dividing by two every time. The second
thing he is saying is that why divide by 2
259
00:44:17,950 --> 00:44:18,930
at all.
260
00:44:18,930 --> 00:44:25,930
In the simple DDA, we found out the value
of length at this stage. all that we need
261
00:44:29,260 --> 00:44:36,260
to do is just say length is equal to length
multiplied by 1.5 or some number. If you notice
262
00:44:41,800 --> 00:44:47,490
this value of length will give you a different
set of pixels than what the symmetric DDA
263
00:44:47,490 --> 00:44:52,800
gives. It will not give the same set of pixels.
264
00:44:52,800 --> 00:44:59,680
Because when you are multiplying by 2 to the
power n, this figure 2 to the power 6 equal
265
00:44:59,680 --> 00:45:06,680
to 64 is not equal to 1.5 times length. No,
but why do we get. Why should we have a line
266
00:45:08,890 --> 00:45:13,240
which is the same as a symmetrical algorithm?
There is no reason for you to have the same
267
00:45:13,240 --> 00:45:15,900
line as such.
268
00:45:15,900 --> 00:45:21,940
But what I am saying is just you can do something
like this, you will get a different set of
269
00:45:21,940 --> 00:45:28,350
pixels. Whether this is more efficient than
the symmetric DDA that I won't say for the
270
00:45:28,350 --> 00:45:35,350
simple reason that we are having what is called
divisions over here. We are having two divisions;
271
00:45:37,990 --> 00:45:44,990
divisions are more expensive than dividing
by 2. So this algorithm is likely to be less
272
00:45:45,450 --> 00:45:52,190
sufficient than the symmetric DDA. The advantage
that symmetric DDA has over a simple DDA is
273
00:45:52,190 --> 00:45:59,190
its speed because there is no division involved
and we are only doing a left shift. So the
274
00:46:01,130 --> 00:46:06,590
advantage of the simple DDA is the speed.
If you use this as modified algorithm then
275
00:46:06,590 --> 00:46:11,480
we lose that advantage. Yes, this algorithm
will also work. You will get a set of pixels
276
00:46:11,480 --> 00:46:18,480
which will be able to display that line but
the disadvantage compared to the symmetric
277
00:46:18,880 --> 00:46:25,880
DDA would be the loss in speed. So we are
just comparing the two algorithms. We said
278
00:46:32,630 --> 00:46:39,630
in simple DDA there is no reputation of pixels
but simple DDA has divisions. Divisions make
279
00:46:55,970 --> 00:46:58,600
the algorithm much slower.
280
00:46:58,600 --> 00:47:05,600
We will now see another algorithm
281
00:47:17,170 --> 00:47:24,170
which is called the Bresenhem's line drawing
algorithm. We will describe the basic principle
282
00:47:25,690 --> 00:47:32,690
of this algorithm today and then we will go
on to the details in the next lecture. I say
283
00:47:43,760 --> 00:47:49,960
this is the array of pixels and you want to
draw a line from one point here to some point
284
00:47:49,960 --> 00:47:56,960
here. Now this line is what your line should
actually look like, so we will call this as
285
00:48:05,940 --> 00:48:12,940
the true line. Now if you actually select
a set of pixels let's say this is one pixel
286
00:48:22,820 --> 00:48:28,420
I select, maybe this is the next pixel I select,
this is another pixel, this is one pixel,
287
00:48:28,420 --> 00:48:35,420
this is one pixel and so on. When I am selecting
this pixel actually if I consider center,
288
00:48:36,190 --> 00:48:43,190
this is the point that has been selected or
if I am talking of the starting plane this
289
00:48:47,840 --> 00:48:54,840
is the place, this is the point which has
been selected. The distance of this point
290
00:48:56,930 --> 00:49:03,930
from this line is this. When I select the
next pixel let's say this one, the pixel that
291
00:49:13,050 --> 00:49:19,520
has been selected is at this location, I am
talking of at the start of the pixel this
292
00:49:19,520 --> 00:49:26,520
is the point. So here the distance of this
location from this true line is this much.
293
00:49:32,500 --> 00:49:38,920
So the set of pixels that are actually displayed
these constitute what we call as the displayed
294
00:49:38,920 --> 00:49:45,920
line, this straight line that I have drawn
that is the true line.
295
00:49:51,470 --> 00:49:58,230
Now the Bresenhem's line drawing algorithm
works on the principle that the distance between
296
00:49:58,230 --> 00:50:05,230
these two lines should be the minimum. This
distance e that is actually the error that
297
00:50:06,420 --> 00:50:13,420
is there between the displayed line and the
true line. So this e is the error or we will
298
00:50:20,480 --> 00:50:27,480
say gap between
true line and displayed line and the Bresenhem's
line drawing algorithm works on the principle
299
00:50:38,840 --> 00:50:45,840
of minimizing this error. again please. Is
somehow like root means square distance minimizing.
300
00:50:55,690 --> 00:51:01,390
We will come to that. Whether we consider
the root mean square distance, the perpendicular
301
00:51:01,390 --> 00:51:06,200
distance or the distance along the x axis
or the distance along y axis we will come
302
00:51:06,200 --> 00:51:06,650
to that soon.
303
00:51:06,650 --> 00:51:12,060
Essentially what we do is just to give a brief
idea, we take the direction of maximum movement
304
00:51:12,060 --> 00:51:19,060
and we measure the error in a direction perpendicular
to that. We will come to that later on. So
305
00:51:19,980 --> 00:51:24,480
the basic idea is that we try to minimize
this error. In the previous algorithm simple
306
00:51:24,480 --> 00:51:31,480
DDA or the symmetric DDA, we were not talking
of this error at all. We were just displaying
307
00:51:32,160 --> 00:51:39,160
pixels in the direction of the slope. We have
not even defined the error; we are not bothered
308
00:51:39,320 --> 00:51:46,320
about whether there is any error between the
displayed line and the true line. So we will
309
00:51:48,400 --> 00:51:54,100
see this algorithm in detail in the next class.
We will stop here now and next time we will
310
00:51:54,100 --> 00:52:01,100
see this algorithm in more detail.