Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Bài giải bài tập Đồ họa máy tính tut7
Nội dung xem thử
Mô tả chi tiết
SOLUTION TUT 7
Câu I:
(left, right, bottom, top) = (30, 220, 50, 240)
Bảng outcode:
1. p1 = (40, 140), p2 = (100, 200)
//Compute Out Code
p1: outcode1 = 0000 p2: outcode2 = 0000
Bước 1: outcode1 | outcode2 = 0000
Đoạn thẳng p1p2 thuộc vùng nhìn thấy.
2. p1 = (10, 270), p2 = (300, 0)
//Compute Out Code
p1: outcode1 = 1001 p2: outcode2 = 0110
Bước 1: outcode1 | outcode2 = 1111
Bước 2: outcode1 & outcode2 = 0000
Giao một phần.
Bước 3: outcode1 & 1000 = 1000
Tính giao điểm:
x = x1 + (x2 – x1) * (top – y1) / (y2 – y1)
= 10 + (300-10) * (240 – 270) / (0 – 270) =42.22
y = top = 240
outcode của giao điểm: 0000
// Gán p1= p2(300,0) ; p2 = (x ,y)= (42.22 ,240)
// Lặp
p1: outcode1 = 0110 p2: outcode2 = 0000
Bước 1: outcode1 | outcode2 = 0110
Bước 2: outcode1 & outcode2 = 0000
Giao một phần.
Bước 3: outcode1 & 1000 = 0000
outcode1 & 0100 = 0100
Tính giao điểm:
x = x1 + (x2 – x1) * (bottom – y1) / (y2 – y1);
= 300 + (42.22-300) * (50 – 0) / (240 – 0)
= 246.29
y = bottom = 50
outcode của giao điểm: 0010
// Gán p1= (x ,y)= (246.29 ,50) ; p2 =(42.22 ,240)