home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!yorkohm!minster!john
- From: john@minster.york.ac.uk
- Newsgroups: comp.graphics
- Subject: Clipping polygon to rectangle
- Message-ID: <724442088.9285@minster.york.ac.uk>
- Date: 15 Dec 92 17:54:49 GMT
- Organization: Department of Computer Science, University of York, England
- Lines: 43
-
- I have read the subsections of ``Computer graphics: principles
- and practice'' [Foley90], which describe algorithms for clipping a
- polygon to a rectangle. None of the algorithms there meet my desire
- for correctness with simplicity and practicality. (I do not require
- completeness, as I am prepared to accept the output of a single degenerate
- polygon instead of a list of disjoint polygons.) I've not found
- anything better in older graphics textbooks, or in a brief literature
- search. (Ok, so I'm crying for the moon - but someone out there
- probably has a method of reaching it. :-))
-
- The Sutherland-Hodgman algorithm (described in [Foley90] and older
- graphics texts I have read) clips against each side of the
- rectangle in turn, and produces three intermediate polygons - which
- I assume require a (single, extra) temporary buffer to hold them.
- This I do not like. As I am prepared to accept the output of degenerate
- polygons, the Liang-Barsky algorithm (again in [Foley90]) sounds as
- if it will satisfy me. Unfortunately, the original paper [Liang83]
- indicates that the algorithm ``will sometimes generate extraneous
- turning vertices'' (p.870). Experimentation with my typed-in copy of
- the LB implementation confirms this warning. Foley, van Dam et. al.
- say that they have modified their implementation (p.932 ``The original
- algorithm operates in a slightly different order'') but this does not
- appear to correct (was not meant to correct?) the problem - in my
- typed-in copy of the FD et. al. code. (Note also that even the Nov.
- 1991 corrected printing of Foley et. al. has typographical errors in
- the code which I had to correct in my typed-in copy before it ran.)
-
- So, can anyone suggest a better algorithm, or a `fixup' for
- the LB algorithm? C implementations preferred. :-) I don't really
- wish to reinvent the wheel.
-
- John A. Murdie
-
- 1. ``Computer graphics: principles and practice'',
- Foley, van Dam, et. al
- Addison-Wesley
- Nov. 1991
-
- 2. ``An analysis and algorithm for polygon clipping'',
- Y.-D. Liang and B. A. Barsky,
- Comm. ACM 26(11) pp.868-877,
- Nov. 1983.
- (Also corrigendum in CACM 27(2), Feb. 1984, p.151.
-