TAILIEUCHUNG - Thuật toán Algorithms (Phần 33)

Tham khảo tài liệu 'thuật toán algorithms (phần 33)', khoa học tự nhiên, toán học phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | ELEMENTARY GEOMETRIC METHODS 313 function same l . line pl p2 point integer var dx dy dxl dx2 dyl dy2 integer begin dx dy dxl pl .x dyl y dx2 dy2 same dx dyl dy dxl dx dy2 dy dx2 end In terms of the variables in this program it is easy to check that the quantity dx dyi dy dxi is 0 if pl is on the line positive if pl is on one side and negative if it is on the other side. The same holds true for the other point so the product of the quantities for the two points is positive if and only if the points fall on the same side of the line negative if and only if the points fall on different sides of the line and 0 if and only if one or both points fall on the line. We ll see that different algorithms need to treat points which fall on lines in different ways so this three-way test is quite useful. This immediately gives an implementation of the intersect function. If the endpoints of both line segments are on opposite sides of the other then they must intersect. function line boolean begin intersect same ll 0 and same 12 0 end Unfortunately there is one case where this function returns the wrong answer if the four line endpoints are collinear it always will report intersection even though the lines may be widely separated. Special cases of this type are the bane of geometric algorithms. The reader may gain some appreciation for the kind of complications such cases can lead to by finding a clean way to repair intersect and same to handle all cases. If many lines are involved the situation becomes much more complicated. Later on we ll see a sophisticated algorithm for determining whether any pair in a set of N lines intersects. Simple Closed Path To get the flavor of problems dealing with sets of points let s consider the problem of finding a path through a set of N given points which doesn t 314 CHAF TER 24 intersect itself visits all the points and returns to the point at which it

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.