Line Clipping Algorithms: Cohen Sutherland
Line Clipping Algorithms: Cohen Sutherland
Cohen Sutherland
i=-128, j=127
Why the line must be clipped?
Basic algorithm:
• Computing all four projections P1, P2, P3, P4.
• Reordering.
• Clipping.
Resume
Basic algorithm:
• Computing all four projections P1, P2, P3, P4 ← TIME DEMANDING !
• Reordering.
• Clipping.
Resume
Basic algorithm:
• Computing all four projections P1, P2, P3, P4 ← TIME DEMANDING !
• Reordering.
• Clipping.
Improvement:
• Analysis of position of A,B.
• Loop on i:
• { Find Pi.
• Put Pi into the right position.
• Clip.
• }
Resume
Basic algorithm:
• Computing all four projections P1, P2, P3, P4 ← TIME DEMANDING !
• Reordering.
• Clipping.
Improvement:
• Analysis of position of A,B.
• Loop on i: ← Not necessary 4x - exit depends on A,B,Pi.
• { Find Pi.
• Put Pi into the right position.
• Clip.
• }
Improvement:
• Analysis of position of A,B.
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Improvement:
• Analysis of position of A,B.
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Improvement:
• Analysis of position of A,B.
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Cohen -Sutherland
Example of non-empty clip
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Cohen -Sutherland
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Cohen -Sutherland
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Cohen -Sutherland
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Cohen -Sutherland
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Cohen -Sutherland
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Cohen -Sutherland
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Cohen -Sutherland
Non-empty clip
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Cohen -Sutherland
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Cohen -Sutherland
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Cohen -Sutherland
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Cohen -Sutherland
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Cohen -Sutherland
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.
Cohen -Sutherland
Empty clip
1. Find C(B).
2. Find C(A).
3. if (C(A)=0000 and C(B)=0000) then clip=(A,B).
End.
4. if C(A)*C(B) ≠ 0000 then clip=empty. End.
5. if C(A)=0000 then swap(A,B).
6. Find intersection P with pi, where C(A)i =1.
7. A=P. GO TO 2.
8. End.