1
00:01:10,930 --> 00:01:17,930
Today we will talk about windowing and clipping.
If you are modeling any object and the coordinates
2
00:01:19,180 --> 00:01:25,660
can start from minus infinity to plus infinity.
In this infinite range in these coordinates
3
00:01:25,660 --> 00:01:32,660
which are normally referred to as the world
coordinate system. Out of this infinite range
4
00:01:37,979 --> 00:01:43,570
we will normally take a finite portion of
this range. Let's say starting from this value
5
00:01:43,570 --> 00:01:50,570
which we will call as Xmin and going up to
Xmax and in the y direction from Ymin to Ymax.
6
00:02:00,310 --> 00:02:07,310
If we take this finite portion of this infinite
world, we will normally like to map this finite
7
00:02:09,140 --> 00:02:16,140
portion on to the screen coordinates. So if
this is a size of a screen let's say this
8
00:02:21,390 --> 00:02:28,390
being a 0 0 and this being the maximum in
terms of x and y. We will normally like this
9
00:02:31,310 --> 00:02:38,310
window to be mapped down to a finite portion
of this screen maybe we will take the full
10
00:02:38,560 --> 00:02:45,560
screen or maybe we can even take a portion
of the screen. What we would like to do is
11
00:02:48,660 --> 00:02:55,660
this portion of the world, we will to map
on to this portion of the screen, so this
12
00:02:57,500 --> 00:03:04,500
is referred to as the screen coordinate system.
13
00:03:11,190 --> 00:03:16,390
In this screen coordinate system the x and
the y values will again range from let's say
14
00:03:16,390 --> 00:03:23,390
if you call this as the x viewing minimum
and this is the x viewing maximum. Similarly
15
00:03:29,620 --> 00:03:36,620
this is the y viewing minimum sorry this will
be the y viewing maximum and this will be
16
00:03:46,780 --> 00:03:53,780
the y viewing minimum. Now this finite portion
is referred to as the window, this is the
17
00:04:05,310 --> 00:04:12,310
window out of the infinite world. A window
is thus a finite portion of the infinite world.
18
00:04:13,760 --> 00:04:20,760
This portion is referred to as the viewport;
this is a part of the complete screen on which
19
00:04:27,150 --> 00:04:31,680
this window is to be displayed.
20
00:04:31,680 --> 00:04:37,660
So if we have any objects inside this window,
you will like this object to be displayed
21
00:04:37,660 --> 00:04:44,660
here like this. Similarly if we have a line
here, we like that line to be displayed here.
22
00:04:51,770 --> 00:04:58,770
When this line is displayed here, its size
as well its coordinates they will be very
23
00:04:59,380 --> 00:05:06,380
different from the size and the coordinates
over here. These coordinates are what are
24
00:05:08,479 --> 00:05:12,720
termed as the world coordinates system, these
coordinates will be in the screen coordinate
25
00:05:12,720 --> 00:05:19,720
system. Typically let's say if you have a
screen has a resolution of 1 0 2 4 plus 1
26
00:05:23,210 --> 00:05:30,210
0 2 4 and these coordinates will be in this
range between 0 and 1023. This xy maximum
27
00:05:32,860 --> 00:05:39,860
would then be 1 0 2 3, 1 0 2 3. So these coordinates
will be in this range but these coordinates
28
00:05:42,240 --> 00:05:49,240
can be in minus infinity to plus infinity
and if they are within this window, they will
29
00:05:50,879 --> 00:05:57,879
be in the range of between Ymin and Ymax and
Xmin and Xmax. How do we transform the coordinates
30
00:05:59,830 --> 00:06:05,659
of let's say the coordinates of this point
on to this point? We have some transformations,
31
00:06:05,659 --> 00:06:07,629
we will go into the transformations later
on.
32
00:06:07,629 --> 00:06:14,099
Today what we will see is and let's say in
this window, if we have a line which is going
33
00:06:14,099 --> 00:06:21,099
like this or if you have a line which is outside
this window, we need to know that this line
34
00:06:26,620 --> 00:06:33,460
is outside the window so that we don't draw
it over here. This line should not be drawn
35
00:06:33,460 --> 00:06:40,110
on this because this viewport is supposed
to draw only those lines or those entities
36
00:06:40,110 --> 00:06:47,110
which are inside this window. So if you have
a line like this that should not be drawn
37
00:06:48,159 --> 00:06:53,340
and if we have a line like this, this line
should only be drawn partially like this.
38
00:06:53,340 --> 00:07:00,340
The rest of the line should not be drawn.
So we will say that this line should be clipped
39
00:07:00,960 --> 00:07:07,960
along this edge that means whatever is outside
this edge, outside this window that should
40
00:07:09,039 --> 00:07:16,039
not be drawn. Is that okay? So that is what
we mean by clipping. Whatever is inside that
41
00:07:22,499 --> 00:07:27,080
should be drawn completely, whatever is outside
the window that should not be drawn, whatever
42
00:07:27,080 --> 00:07:34,080
is partially inside and partially outside
that should be cut along the edges. If you
43
00:07:34,669 --> 00:07:41,669
have a circle like this, only this part of
the arc should be drawn. If you have a triangle
44
00:07:43,409 --> 00:07:50,409
like this, only this part of the triangle
should be drawn. We do not want to draw anything
45
00:07:52,300 --> 00:07:59,300
outside the viewport obviously. So we will
just see how this clipping can be done.
46
00:08:22,620 --> 00:08:29,620
If this is the window, if these are the four
boundaries of this window what we have to
47
00:08:48,220 --> 00:08:55,220
ensure? An edge like this should get clipped
at these two intersection points and edge
48
00:08:57,410 --> 00:09:04,410
like this should not be drawn at all and edge
like this should be clipped here. Only a portion
49
00:09:09,029 --> 00:09:15,490
inside that should be displayed. And how do
we do that? Let's say this is the one end
50
00:09:15,490 --> 00:09:22,490
point, this is the second end point. How do
we clip it along the intersection point? We
51
00:09:23,790 --> 00:09:30,790
will need to find the intersection of this
line with the line x equal to Xmin. Similarly
52
00:09:31,510 --> 00:09:36,590
we will need to find the intersection of the
line P1 P2 with the line y equal to Ymax.
53
00:09:36,590 --> 00:09:43,590
For this line let's say this is P3 and this
is P4, for the line P3 P4 you will have to
54
00:09:47,050 --> 00:09:54,050
find out the intersection with the line x
equal to Xmin and x equal to Xmax. We have
55
00:09:55,420 --> 00:10:01,519
to find all these intersections and is very
important that all this to be done as efficiently
56
00:10:01,519 --> 00:10:08,519
as possible. Efficiency is of prime concern
because this clipping is done very frequently
57
00:10:13,959 --> 00:10:17,180
and whenever this clipping is done typically
you will have a number of entities in the
58
00:10:17,180 --> 00:10:24,180
world. So we like to do it as efficiently
as possible so that the clipping should be
59
00:10:27,170 --> 00:10:34,170
done fast. Speed is of prime concern. One
way of increasing the efficiency is that if
60
00:10:37,100 --> 00:10:43,250
you can know for sure that some lines are
outside, let's say if we have a line like
61
00:10:43,250 --> 00:10:50,250
this, if a line is outside this window I should
not try to find out the intersection of this
62
00:10:52,740 --> 00:10:55,769
line with each of the four boundaries.
63
00:10:55,769 --> 00:11:02,769
Let's say for a line like this AB, if I try
to find the intersection AB with either of
64
00:11:06,899 --> 00:11:13,899
these lines Xmin, Xmax, Ymin and so on. If
you find any of these intersections, this
65
00:11:16,750 --> 00:11:23,750
exercise is going to be wasteful because this
line is totally outside and wherever the intersections
66
00:11:24,170 --> 00:11:29,310
like, irrespective of that the line is not
going to be displayed. So the first thing
67
00:11:29,310 --> 00:11:36,310
that we normally do is we try to see if a
particular line is totally out of the window.
68
00:11:36,820 --> 00:11:42,490
If that line is totally outside the window
that is it is either above the Ymax line or
69
00:11:42,490 --> 00:11:48,019
below the Ymin line or to the right of the
Xmax line or to the left of the Xmin line,
70
00:11:48,019 --> 00:11:55,019
at least such lines should be moved all together.
I should not try to clip them or find the
71
00:11:57,360 --> 00:12:04,360
intersections with the boundaries. So the
first thing that we will do is identify
invisible lines.
72
00:12:23,839 --> 00:12:30,839
Similarly if a line is completely inside if
the line is completely inside even though
73
00:12:33,269 --> 00:12:40,269
I need not find out the intersections
because the line is inside there is no point
in finding out the intersections. I have to
74
00:12:44,649 --> 00:12:51,649
draw the complete line anyway. So I will again
try to identify completely visible lines and
75
00:13:05,850 --> 00:13:12,509
only for lines which are partially visible,
lines which are partially inside the window
76
00:13:12,509 --> 00:13:17,410
and partially outside we should try to find
out the intersection with the edges of the
77
00:13:17,410 --> 00:13:24,410
window. And then for partially visible lines
we will find out the intersection and so on.
78
00:13:37,759 --> 00:13:44,759
For this we will have a different set of steps.
How do we identify whether a line is completely
79
00:13:46,319 --> 00:13:53,319
visible or completely invisible? I said one
way is that lines which are totally above
80
00:13:53,350 --> 00:14:00,350
the Ymax line will always be totally invisible.
How do I check whether a line segment AB is
81
00:14:01,899 --> 00:14:06,829
totally above the Ymax line? I will have to
compare the y coordinates of the points A
82
00:14:06,829 --> 00:14:08,139
and B.
83
00:14:08,139 --> 00:14:15,139
So I can say if Y of A is greater than Ymax
and Y of B is also greater than Ymax then
84
00:14:21,480 --> 00:14:28,480
the line is invisible. Similarly I can have
constraints for each of the four lines. So
85
00:14:30,779 --> 00:14:37,779
if Y of A is less than Ymin and Y of B is
also less than Ymin that means the line is
86
00:14:39,940 --> 00:14:46,940
somewhat like this, even then the line will
be totally invisible. Instead of checking
87
00:14:52,569 --> 00:14:58,639
for constraints like this, checking such constraints
a number of times can become slightly messy,
88
00:14:58,639 --> 00:15:05,639
instead of that we use what is called as the
four point code.
89
00:15:42,350 --> 00:15:49,350
With respect to every line let's say if you
take a point here, if we take a point here,
90
00:15:53,540 --> 00:16:00,540
now this point is to the left of the line
Xmin, it is above the line Ymin but below
91
00:16:01,449 --> 00:16:08,449
the line Ymax. So with respect to every edge,
we will give it a one point code. So for this
92
00:16:12,829 --> 00:16:19,829
point if we have 1 2 3 4, since this point
is to the left of the Xmin line we will give
93
00:16:21,620 --> 00:16:28,620
it a code of one. If it is above the Ymin
line, we will give it a code of zero. It is
94
00:16:38,209 --> 00:16:45,209
below the Ymax line we will give it a code
of zero and it is to the left of the Xmax
95
00:16:45,889 --> 00:16:52,889
line we will give it a code of zero. So if
any point is to the left of the Xmax line,
96
00:16:58,389 --> 00:17:05,389
mind you the visible portion is also to the
left of the Xmax line. If any point is to
97
00:17:06,470 --> 00:17:13,470
the left of this Xmax line corresponding to
that we give it a code of zero. If this point
98
00:17:16,220 --> 00:17:23,220
was to the right of Xmin line, we will again
give it a code of zero. So with respect to
99
00:17:26,560 --> 00:17:33,560
Xmin, Xmax, Ymin and Ymax with respect to
each of them our code will be either 0 or
100
00:17:44,000 --> 00:17:51,000
1. If you are to the left of Xmin, we will
give it a code of one. If you are to the right
101
00:17:55,220 --> 00:18:01,420
of Xmin, we will give it a code of zero. If
you are to the left of the Xmax we will give
102
00:18:01,420 --> 00:18:08,420
it a code of zero, if you are to the right
we will give it a code of one. If I take Ymin,
103
00:18:10,200 --> 00:18:17,200
if I am below Ymin then I will give it a code
of one, if I am above I will give it a code
104
00:18:17,470 --> 00:18:22,090
of zero.
105
00:18:22,090 --> 00:18:27,450
Similarly Ymax, if I am below Ymax I will
give it a code of zero, if I am above Ymax
106
00:18:27,450 --> 00:18:34,450
I will give it a code of, if it is above Ymax
I will it code of one. As a result if a point
107
00:18:41,400 --> 00:18:48,400
is inside this region, it will get a code
of 0 0 0 0. If a point is in this region,
108
00:19:00,410 --> 00:19:07,410
the point is below Ymin so it gets a code
of let's say this is a Ymax, this is a Ymin,
109
00:19:11,080 --> 00:19:18,080
Xmax and Xmin. So if this is a Ymax, if it
is below Ymax it gets a code of 0, if it is
110
00:19:20,940 --> 00:19:27,940
below Ymin it gets a code of one. It is to
the left of Xmin, left of Xmin; Xmin means
111
00:19:29,190 --> 00:19:36,190
one and to the left of Xmax also, so it will
get zero. So this code I am using for the
112
00:19:39,600 --> 00:19:46,600
first bit, I am using with respect to Xmin
this I am using with respect to Xmax, this
113
00:19:48,530 --> 00:19:55,530
I am using with respect to Ymin and this with
respect to Ymax. If I then if the point is
114
00:20:05,010 --> 00:20:12,010
in this region what code will it get? the
first bit with respect to Xmin would be zero,
115
00:20:12,960 --> 00:20:17,840
with respect to Xmax will also be zero, with
respect to Ymin again we are on the wrong
116
00:20:17,840 --> 00:20:24,840
side so it will be one and this will be zero.
If you are here with respect to Xmax will
117
00:20:28,240 --> 00:20:35,240
be one, this will be zero and this should
be 0 1 and this would probably be 0 0 1 0.
118
00:20:42,260 --> 00:20:49,260
If you come here then with respect to Ymax,
1 0 0 1 and this would become...
119
00:20:49,780 --> 00:20:56,780
So in these 9 regions the point will get a
different code. If a point is here it becomes
120
00:21:09,660 --> 00:21:16,660
1 0 0 1, if it is here it gets 1 0 0 0 and
so on. Now if one point is here and a second
121
00:21:19,790 --> 00:21:26,790
point is here, both of them will get the code
of 0 0 0 1. If one point is here and the other
122
00:21:28,770 --> 00:21:35,770
point is here, this will get a code of 0 1
0 1, this will get a code of 1 0 0 1. Both
123
00:21:37,330 --> 00:21:44,330
these points are to the left of Xmin, so the
bit corresponding to Xmin will be one for
124
00:21:45,130 --> 00:21:52,130
both of them. So if I take any line segment
and out of the four bits, any one bit is one
125
00:21:58,330 --> 00:22:05,330
for both the end points that would mean the
line is totally outside the window. If I take
126
00:22:07,990 --> 00:22:14,990
a point here and a point here, in that case
I get a, with respect to Ymin both the points
127
00:22:17,530 --> 00:22:24,530
are lying below. So Ymin, so this third bit
here and a third bit here both will be one.
128
00:22:27,790 --> 00:22:34,790
So if I take the code for point one and the
code for point two and I take the intersection
129
00:22:44,260 --> 00:22:51,260
of these codes. In the intersecting of these
codes has a one at any location or the intersection
130
00:22:54,500 --> 00:23:01,500
of these codes is not equal to zero, in that
case the line segment will be totally out
131
00:23:02,860 --> 00:23:09,860
of the window. Is that okay? So if the code
for point one intersection in the code for
132
00:23:13,040 --> 00:23:20,040
point two is not equal to zero that means
line is invisible, completely invisible.
133
00:23:32,150 --> 00:23:38,160
Similarly if I have a point here and a point
here then the code for both of them has to
134
00:23:38,160 --> 00:23:45,160
be 0 0 0 0. So if I say that the code for
point one union with the code for point two
135
00:23:50,340 --> 00:23:57,340
is equal to zero then the line is completely
visible. If the line is inside then both the
136
00:24:24,490 --> 00:24:30,800
endpoints will have a code of 0 therefore
the union will be equal to 0. If the line
137
00:24:30,800 --> 00:24:37,800
is to one side of either of the 4 edges then
the corresponding bit will be one and therefore
138
00:24:39,090 --> 00:24:46,090
the intersection will not be equal to 0 and
then the line will be totally invisible and
139
00:24:48,080 --> 00:24:54,420
these bits can easily be set for each point
just by comparing them with the x and the
140
00:24:54,420 --> 00:25:01,420
y coordinates of the edges. So by using this
fourth and the four bit code, this is a four
141
00:25:03,290 --> 00:25:10,290
bit code. By using this four bit code we can
very easily check whether the line is completely
142
00:25:13,280 --> 00:25:20,000
invisible or whether the line is completely
visible.
143
00:25:20,000 --> 00:25:27,000
Of course there will be some cases like this.
If we take this 0 1 0 0 and 0 0 1 0, their
144
00:25:34,930 --> 00:25:41,930
intersection will be equal to 0 but even then
the line is completely invisible. In such
145
00:25:49,500 --> 00:25:56,500
cases these checks are not going to result
in any decision, we cannot say, we cannot
146
00:25:57,880 --> 00:26:03,040
decide on the basis of these checks that the
line is invisible. Only when the intersection
147
00:26:03,040 --> 00:26:10,040
is not equal to zero will the line be invisible.
Only when the intersection is not equal to
148
00:26:10,630 --> 00:26:14,930
zero, we can say confidently that the line
is invisible but if this condition is not
149
00:26:14,930 --> 00:26:21,430
satisfied and this condition is also not satisfied
then the line can be invisible or the line
150
00:26:21,430 --> 00:26:28,430
can be partially visible. Whether the line
is like this or the line is like this, we
151
00:26:30,610 --> 00:26:37,610
can decide that only by finding out the intersection
points. So this four bit code will help us
152
00:26:44,940 --> 00:26:51,940
in reading out those lines which satisfy either
this criteria or this criteria. Any question
153
00:26:59,000 --> 00:27:06,000
up to this point? Then for the other lines
for lines like this, for lines like this how
154
00:27:16,860 --> 00:27:23,860
do we go about clipping these lines? The first
is we check for these lines and then start
155
00:27:25,230 --> 00:27:27,150
finding out the intersections.
156
00:27:27,150 --> 00:27:34,150
So we write it crudely. The first step is
find four point codes
for P1 and P2. We are trying to clip the line
157
00:27:50,660 --> 00:27:57,660
segment P1 P2 then find the four point codes
for P1 P2 then we check for these conditions
158
00:27:58,860 --> 00:28:05,860
let's say condition one and condition two.
We will check for these conditions condition
159
00:28:06,530 --> 00:28:13,530
one and condition two. So I will just right
if condition one is satisfied then line is
160
00:28:20,590 --> 00:28:27,590
invisible, neglected. If condition two is
satisfied then line is visible, draw it. Otherwise
161
00:28:51,540 --> 00:28:58,540
what will we do? We find out the intersections
of P1 P2 with the window border and check
162
00:29:23,600 --> 00:29:26,770
which part is inside and which part is outside.
163
00:29:26,770 --> 00:29:33,770
We will have to find out the intersection
of this edge with all the four edges, all
164
00:29:36,530 --> 00:29:42,600
the four edges of the window we will get one
intersection here, the other intersection
165
00:29:42,600 --> 00:29:46,960
here. We will say that these two intersections
are outside this line segment, so we will
166
00:29:46,960 --> 00:29:53,030
ignore that. We will find out this intersection
and this intersection and then decide that
167
00:29:53,030 --> 00:29:58,020
this line is outside, this line is inside
and this line is outside and we finally display
168
00:29:58,020 --> 00:30:05,020
this edge. So in this fourth step we will
have to find out the intersection with each
169
00:30:06,160 --> 00:30:13,160
of the four edges of the window and check
as to which part of the line segment is inside
170
00:30:14,910 --> 00:30:21,910
and which part is outside. This is one clipping
algorithm for line segments. Any question
171
00:30:38,570 --> 00:30:45,570
about this clipping algorithm? We will just
modify this clipping algorithm to increase
172
00:30:47,120 --> 00:30:54,120
speed further, how to make it more efficient.
Any question about this clipping algorithm?
173
00:30:59,970 --> 00:31:06,970
We will now see a clipping algorithm which
is attributed to Sutherland
and Cohen. Sutherland and Cohen are the name
174
00:31:42,910 --> 00:31:49,910
of two scientists who developed this algorithm.
Now the problem with previous algorithms that
175
00:31:51,230 --> 00:31:58,230
comes is that when we have a line like this,
we have to find out the intersection of this
176
00:32:10,210 --> 00:32:17,210
line with each of the four edges of the window.
We first find out let's say this intersection,
177
00:32:17,340 --> 00:32:23,410
will then I also have to check whether this
intersection is inside the line segment or
178
00:32:23,410 --> 00:32:30,410
not. Since this intersection is outside is
really not relevant, only an intersection
179
00:32:30,570 --> 00:32:37,570
which is inside this line segment is going
to be relevant.
180
00:32:40,670 --> 00:32:45,820
Similarly at this point, this intersection
is also outside this line segment so that
181
00:32:45,820 --> 00:32:52,820
is also not relevant. In order to take care
of all these, what we can do is let's say
182
00:32:55,410 --> 00:33:02,410
this is our clipping edge and we have a line
to be clipped which is a line like this. I
183
00:33:05,340 --> 00:33:12,340
call this as the correct side of the clipping
edge, this is my clipping edge
and this as the wrong side. Again please?
184
00:33:23,100 --> 00:33:30,100
The correct side is the visible side. The
correct side is the visible side and the wrong
185
00:33:31,990 --> 00:33:36,360
side is the wrong side. So if I am considering
this as my clipping edge, the right hand side
186
00:33:36,360 --> 00:33:43,360
of the visible edge or the correct side and
left hand side is the wrong side.
187
00:33:43,680 --> 00:33:50,680
Now if I have a line segment whose both the
end points are on the correct side then no
188
00:33:54,290 --> 00:34:01,070
clipping has to be performed with respect
to the clipping edge as straight forward.
189
00:34:01,070 --> 00:34:08,070
Similarly if I have a line segment which has
both its end points on the wrong side even
190
00:34:09,730 --> 00:34:16,730
then no clipping has to be performed with
respect to this edge. Only when I have one
191
00:34:17,970 --> 00:34:23,270
end point on one side and the other end point
on the other side. I have one end point which
192
00:34:23,270 --> 00:34:28,290
is P1 which is on the correct side and P2
which is on the wrong side. Only in that case
193
00:34:28,290 --> 00:34:35,290
do I need to perform the clipping. So in the
Sutherland Cohen clipping algorithm, we will
194
00:34:35,770 --> 00:34:38,750
perform clipping with respect to each edge
separately.
195
00:34:38,750 --> 00:34:44,820
Let's say this is my edge number 1, this is
my edge number 2, this is edge my number 3
196
00:34:44,820 --> 00:34:51,820
and this is my edge number 4. I will first
perform clipping with respect to edge number
197
00:34:52,280 --> 00:34:59,280
1 and I will check whether both the end points
are on the correct side or both of them are
198
00:35:01,839 --> 00:35:07,930
on the wrong side. If both of them are in
the correct side, no clipping has to be performed
199
00:35:07,930 --> 00:35:13,760
with respect to edge number one. If both of
them are on the wrong side again no clipping
200
00:35:13,760 --> 00:35:20,760
needs to be performed, the line can be ignored.
If one point is on one side, the other is
201
00:35:23,210 --> 00:35:30,210
on the other side, I find out the intersection
and the line from the point P1 to this intersection
202
00:35:30,980 --> 00:35:37,980
point I, this is the line we are intersected
in. So I will just write down this algorithm.
203
00:36:10,160 --> 00:36:17,160
We will repeat with respective to each window
edge. The first thing is check whether the
204
00:36:58,470 --> 00:37:03,359
line is completely visible or completely invisible
that means both the points are on the correct
205
00:37:03,359 --> 00:37:10,359
side or both the points are on the wrong side.
If either of the two conditions is satisfied
206
00:37:12,430 --> 00:37:19,430
then we can take action accordingly and complete
and come out of the algorithm. Otherwise what
207
00:37:26,609 --> 00:37:33,609
we will do is CS is for correct side. I will
just explain what we are doing. What I said
208
00:38:44,089 --> 00:38:51,089
is if P1 is on the correct side continue else
swap P1 and P2. In this case P1 is on the
209
00:38:55,329 --> 00:39:02,329
correct side, P2 is on the wrong side. There
is no problem but if my line segment or like
210
00:39:06,220 --> 00:39:13,220
this and this was P1 and this was P2. P1 is
on the wrong side and P2 on the correct side.
211
00:39:14,740 --> 00:39:21,740
I want to exchange the points P1 and P2, I
want to call this as P1 and this as P2, I
212
00:39:25,150 --> 00:39:31,289
want to call the point on the correct side
as P1 so that when I find out the intersection
213
00:39:31,289 --> 00:39:38,289
from P1 to the intersection I, that point
I will take as the clip segment.
214
00:39:38,880 --> 00:39:45,880
If this is P1 then from P2 to I, I had to
take P2 to I. I don't want to do that, I want
215
00:39:47,759 --> 00:39:54,759
to take from P1 to I. So this is P1 and this
is P2, I will swap P1 and P2 and still take
216
00:39:55,819 --> 00:40:02,819
the line segment from P1 to I. So if P1 is
on the correct side continue else swap P1
217
00:40:11,779 --> 00:40:18,779
and P2 and then find the intersection of P1
P2 with the edge, with the clipping edge and
218
00:40:20,069 --> 00:40:27,069
clip the line segment P1 P2 to P1 I. Sir why
this swapping necessary? Again please. Why
219
00:40:27,809 --> 00:40:34,809
this swapping on the points P1 and P2 necessary?
If I don't swap but I have to check for is
220
00:40:37,829 --> 00:40:42,779
which point is on the correct side and which
is on the wrong side. If P2 is on the correct
221
00:40:42,779 --> 00:40:49,779
side then the clipped line will be P2 I and
not P1 I. Is that okay?
222
00:40:51,920 --> 00:40:55,839
So I will have to keep track of whether P1
is on the right side or P2 is on the right
223
00:40:55,839 --> 00:41:01,009
side. I don't want to keep extra track of
that. I will just check for that and swap
224
00:41:01,009 --> 00:41:08,009
them and make sure that P1 is on the right
side. So after the step two I know for sure
225
00:41:10,700 --> 00:41:17,700
that P1 is on the correct side and then in
step three I will just find out the intersection
226
00:41:20,700 --> 00:41:27,700
of P1 P2 with the clipping edge and the line
will get clipped to P1 I and then I will take
227
00:41:29,559 --> 00:41:36,559
this line and repeat it and clip it with respect
to the remaining three edges. So first I have
228
00:41:39,029 --> 00:41:46,029
taken, I will repeat this whole process with
respect to edge one then with respect to edge
229
00:41:46,450 --> 00:41:53,450
two and so on, I mean edge 3 and edge 4. The
first step is check for completely visible
230
00:41:59,499 --> 00:42:06,190
or invisible line. If you expand the step
out, if the line is completely invisible then
231
00:42:06,190 --> 00:42:13,190
the clipped line itself is P1 P2. Then this
clipped line P1 P2 will be passed on to the
232
00:42:14,240 --> 00:42:17,789
next edge for further clipping.
233
00:42:17,789 --> 00:42:24,789
If the line is completely invisible in that
case the line to be passed will be on blank
234
00:42:28,349 --> 00:42:33,369
line, no clipping will be done after that
because the line is totally invisible. So
235
00:42:33,369 --> 00:42:38,869
the line is completely invisible where clipping
algorithm can end here. If line is completely
236
00:42:38,869 --> 00:42:45,869
visible then this clipped edge has to be passed
on to the next clipping edge and the process
237
00:42:46,119 --> 00:42:53,119
will have to be repeated for each of the edges.
So this algorithm is called as Sutherland
238
00:42:54,230 --> 00:43:01,230
Cohen algorithm, Sutherland Cohen clipping
algorithm and the important thing in this
239
00:43:01,799 --> 00:43:07,980
algorithm is first clipping is done with respect
to each edge separately and secondly we are
240
00:43:07,980 --> 00:43:14,980
making sure that the point P1 is always on
the correct side so that it becomes easier
241
00:43:15,980 --> 00:43:21,609
to say that P1 I will always be the clipped
edge, otherwise we will have to decide whether
242
00:43:21,609 --> 00:43:28,609
it is P1 I or P2 I. Any question about this
Sutherland Cohen clipping algorithm? Continuing
243
00:43:35,900 --> 00:43:42,900
with clipping further, so far I have been
talking of clipping of line segments only.
244
00:43:44,069 --> 00:43:51,069
If instead of a line segment, if we have let's
say this is the clipping window
and if you have curves, if you have a curve
245
00:44:01,910 --> 00:44:08,910
like this, in a curve it has to be clipped
then clearly the algorithm that you are using
246
00:44:10,630 --> 00:44:17,470
so far will not be valid for this curve. Even
if I take a simple curve, a simple arc like
247
00:44:17,470 --> 00:44:24,470
this even though both the end points of the
arc might be inside, a part of my curve can
248
00:44:26,559 --> 00:44:33,559
still be outside. Again same algorithm will
not work. The second problem is that if we
249
00:44:34,769 --> 00:44:41,769
have regions or an area to be clipped, an
area can be defined by let's say a polygon.
250
00:44:42,230 --> 00:44:49,230
We want this area to be clipped, we like to
clip this to this portion. So if you have
251
00:44:58,869 --> 00:45:04,069
a polygon given as a list of points, a list
of vertices, we like to be able to clip it
252
00:45:04,069 --> 00:45:11,069
and find out the clipped polygon. So with
respect to curves, the way you look clippings
253
00:45:18,730 --> 00:45:25,730
of curves normally will divide this curve
into sequence of small line segments. For
254
00:45:28,339 --> 00:45:35,009
display of curves normally approximated as
the sequence of line segments and then once
255
00:45:35,009 --> 00:45:40,849
it is approximated as a sequence of line segments,
we will do the clipping of line segments.
256
00:45:40,849 --> 00:45:47,849
So the curves they will be reduced to lines
and if you have a closed region bounded by
257
00:45:51,539 --> 00:45:58,539
a polygon, if you want to do the clipping
for polygons then you will have a special
258
00:45:59,150 --> 00:46:01,609
algorithm for that which we will see in the
next class.
259
00:46:01,609 --> 00:46:08,509
How do we carry out a clipping of polygon
so that we can get a clipped polygon? Polygon
260
00:46:08,509 --> 00:46:15,509
is we have seen earlier, they are list of
vertices P1 P2 till Pn. We want to clip this
261
00:46:17,029 --> 00:46:24,029
and get a list of vertices say Q1 Q2 till
Qm where this is the clipped polygon and this
262
00:46:28,210 --> 00:46:33,470
is the origin, P1 is original polygon. How
do we do this? that we will see in the next
263
00:46:33,470 --> 00:46:39,950
class. For curves we will normally approximate
a curve by set of lines and then do the clipping.
264
00:46:39,950 --> 00:46:46,950
Any questions on clipping
265
00:46:57,029 --> 00:47:04,029
that I have covered today.
266
00:47:26,759 --> 00:47:33,369
If you look at this window we say that this
window is a finite portion of the infinite
267
00:47:33,369 --> 00:47:40,369
world. If you want to do the clipping at the
time of displaying the pixel, you decide whether
268
00:47:42,680 --> 00:47:49,039
the pixel is inside or outside. Just imagine
some curve or some entity which had a very
269
00:47:49,039 --> 00:47:54,440
large distance. you also have to display that
and then find out the pixel which will correspond
270
00:47:54,440 --> 00:48:01,440
to that. The idea of clipping is that whichever
portion is outside, you will not try to write
271
00:48:01,480 --> 00:48:07,660
down the or you will not try to run a display
algorithm for that. If you try to run a display
272
00:48:07,660 --> 00:48:13,999
algorithm for that, you will end up doing
lot of wasteful computation. This portion
273
00:48:13,999 --> 00:48:20,299
might be let's say only 1 % of the complete
set of entities you have. If you have a let's
274
00:48:20,299 --> 00:48:27,119
say an entity over here, no point find out
which pixels will correspond to this circle
275
00:48:27,119 --> 00:48:30,150
and for each of those pixels saying that those
pixels are outside the window. Then for the
276
00:48:30,150 --> 00:48:37,150
each line segment we will have to prove that
anyway. So what we are doing now? What we
277
00:48:41,400 --> 00:48:47,539
will do is we will divide this in the line
segments. Initially it can be very close and
278
00:48:47,539 --> 00:48:50,480
find out which line segments are inside and
which are outside.
279
00:48:50,480 --> 00:48:55,759
If we find out that the complete curve is
trivially outside, we will not bother about
280
00:48:55,759 --> 00:49:02,049
it. Then the other thing is for entities like
curves I mean for entities of circles, you
281
00:49:02,049 --> 00:49:07,339
can easily find out the bounds of the circle.
If those bounds are completely outside the
282
00:49:07,339 --> 00:49:14,339
clipping window, we can ignore that circle,
we need not even try to display that or clip
283
00:49:14,450 --> 00:49:21,450
that. Our basic idea is that we will try in
clipping we will try to remove as many entities
284
00:49:22,289 --> 00:49:29,289
as possible without displaying them because
we know the display is slow. Because in display
285
00:49:29,960 --> 00:49:35,529
you are going to compute the detail of each
and every pixel and in fact if you remember
286
00:49:35,529 --> 00:49:40,980
in some of the display algorithms, we were
using space which is proportional to the number
287
00:49:40,980 --> 00:49:47,980
of pixels. So if you are talking of an infinite
space, we really can't do that. We cannot
288
00:49:48,480 --> 00:49:55,480
have infinite number of pixels and decide
the intensity of each pixel and so on. We
289
00:49:55,630 --> 00:50:00,400
will have to, if we try to compute the pixel
corresponding to each of these points depending
290
00:50:00,400 --> 00:50:05,779
on the number of entities that we have can
also become very expensive.
291
00:50:05,779 --> 00:50:12,440
So first thing we do is we try to see whether
this curve has any portion common with the
292
00:50:12,440 --> 00:50:19,440
window. If it does not we ignore that, if
it does only then we try to do the clipping
293
00:50:20,769 --> 00:50:26,559
for that and for that we will approximate
it by a set of lines and then do because then
294
00:50:26,559 --> 00:50:33,559
we know that some portion is going to be common.
Even let's say for a curve like this, if we
295
00:50:35,400 --> 00:50:42,400
start finding out the set of pixels that will
correspond to the invisible part of the curve,
296
00:50:42,440 --> 00:50:46,720
we will have to find out for each of these
pixels we will have find out whether the pixels
297
00:50:46,720 --> 00:50:53,349
are inside or outside that is going to be
wasteful. Instead of that we will divide this
298
00:50:53,349 --> 00:50:55,160
into a sequence of line segments.
299
00:50:55,160 --> 00:51:01,890
Normally what we do is we initially start
with the very close division like this and
300
00:51:01,890 --> 00:51:08,890
only if we feel the need, we will start bringing
them closer. If we feel that let's say from
301
00:51:09,849 --> 00:51:16,849
here to here, a part of the curve is going
to be inside then we will sub divide it further
302
00:51:18,559 --> 00:51:25,559
and so on. We will be seeing more of this
in detail in the later topics. I think at
303
00:51:35,569 --> 00:51:42,569
that point it will become much clearer. Any
other questions? So that's all for today.