Clipping - 4/5/2010 Clipping Cohen‐Sutherland Before...

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 4/5/2010 Clipping Cohen‐Sutherland Before clipping… 1 4/5/2010 After clipping… Point Clipping Display P = (x, y) if •xwmin <= x <= xwmax •ywmin <= y <= ywmax 2 4/5/2010 Line Clipping Display P = (x, y) if •xwmin <= x <= xwmax •ywmin <= y <= ywmax Line Clipping If both points lie inside the window •display segment Line Clipping (cont) Display P = (x, y) if •xwmin <= x <= xwmax •ywmin <= y <= ywmax Line Clipping If both points lie inside the window •display segment If both points lie outside the same boundary •discard segment 3 4/5/2010 Line Clipping (cont) Display P = (x, y) if •xwmin <= x <= xwmax •ywmin <= y <= ywmax If both points lie inside the window •display segment If both points lie outside the same boundary •discard segment If segment crosses one or more boundaries •calculate intersections with boundaries x = x1 + u(x2 - x1) y = y1 + u(y2 - y1) if 0 <= u <= 1 display section within boundary else discard segment Cohen ‐ Sutherland Line Clipping 4 bit clip code: A B R L 4 4/5/2010 Cohen ‐ Sutherland Line Clipping (cont) 4 bit clip code: A B R L A = y > ywmax B = y < ywmin R = x > xwmax L = x < xwmin 4 bit clip code: A B R L A = y > ywmax B = y < ywmin R = x > xwmax L = x < xwmin Calculate clip code P1 = 0 0 0 0 P2 = 0 0 0 0 ‐‐‐ 0 0 0 0 => accept segment P1 P2 (trivial accept since both end points are in the window 5 4/5/2010 4 bit clip code: A B R L A = y > ywmax B = y < ywmin R = x > xwmax L = x < xwmin Calculate clip code P3 = 1 0 0 1 P4 = 1 0 0 0 ‐‐‐ 1 0 0 0 => Reject segment P3 P4 4 bit clip code: A B R L A = y > ywmax B = y < ywmin R = x > xwmax L = x < xwmin 1) Calculate clip code P5 = 0 0 0 1 P7 = 0 0 0 1 P6 = 1 0 0 0 P8 = 1 0 0 0 ‐‐‐ 0 0 0 0 ‐‐‐ 0 0 0 0 => Can accept both (since some point are outside windows, need to further calculate) 6 4/5/2010 2) Clip against left ⇒Calculate new P’5 & P’7 P’5 = (xwmin, y5 + m(xwmin – x5)) P’7 = (xwmin, y7 + m(xwmin – x7)) 3) Update clip code P’5 = 1 0 0 0 P’7 = 0 0 0 0 P6 = 1 0 0 0 P8 = 1 0 0 0 ‐‐‐ 1 0 0 0 ‐‐‐ 0 0 0 0 ⇒Reject P’5 P6 4) Clip against right 5) Clip against bottom 7 4/5/2010 P’7 = 0 0 0 0 P8 = 1 0 0 0 6) Clip against top P’8 = (x7 + (ywmax – y7)/m, ywmax) 7) Update clip code P’7 = 0 0 0 0 P’8 = 0 0 0 0 ‐‐‐ 0 0 0 0 => Accept P’7 P’8 Formula • E.g: P1 (x1,y1) • New points: P’1 P2 (x2,y2) – If the new point intersect with the vertical clipping border: • x is either Xwmin or Xwmax • y = y1 + m (x – x1) • m = (y2 – y1)/(x2 – x1) – If the new point intersect with the horizontal clipping border: • y is either Ywmin or Ywmax • x = x1 + (y – y1)/m 8 4/5/2010 Example (1) • Given: Xwmin = 10, Xwmax = 100, Ywmin = 50, Ywmax = 150 • Line segment: P1 = (50, 70), P2 = (90, 170) P2 150 P1 50 10 100 • Steps: – Calculate the m = (y2‐y1)/(x2‐x1) = (170‐70)/(90‐50) = 100/40 = 2.5 – Calculate new P’2 (x,y):‐ intersect with Ywmax • y = Ywmax = 150 • x = x2 + (y – y2)/m = 90 + (150‐170)/2.5 = 90 – 8 = 82 • New P’2 = (82, 150) 9 4/5/2010 Exercise (2) • With the same window, calculate the new point for a line segment P3 (2,120) and P4 (40,10) using Cohen‐ Sutherland clipping algorithm. 150 P3 50 P4 10 100 • Calculate the m = (10‐120)/(40‐2) = ‐110/38 = ‐2.89 • Calculate new P’3:‐ intersect with Xwmin – x = Xwmin = 10 – y = y3 + m(x‐x3) = 120 ‐ 2.89(10‐2) = 120 – 23.12 = 96.9 • New P’3 (10, 96.9) is inside windows ‐> accept 10 4/5/2010 • Calculate new P’4:‐ intersect with Ywmin – y = Ywmin = 50 – x = x4 + (y‐y4)/m = 40 + (50‐10)/‐2.89 = 40 – 13.8 = 26.2 • New P’4 (26.2, 50) is inside windows ‐> accept Exercise • Given the size of the window is at (left, right, bottom, up) = (100,400,100,450). Using Cohen‐Sutherland clipping algorithm, calculate and the new points for a line segment P1(150, 80) and P2(450, 500). 11 ...
View Full Document

Ask a homework question - tutors are online