|
From: Ethan A M. <merritt@u.washington.edu> - 2008-01-14 03:44:53
|
On Friday 11 January 2008 05:47, Gerard Cats wrote: > > I encountered a problem when I tried to fill a closed polygon which > extended beyond the xrange, yrange. This is conform the documentation, > which says: > "Zoom of a filled curve drawn from a datafile may produce empty or > incorrect area because gnuplot is clipping points and lines, and not areas." > I use Version 4.2 patchlevel 2. > I guess that it is desirable to remove this "feature" from gnuplot. I think you are correct that it would be worth re-visiting the generic filled-area code in gnuplot. I suspect that the existing code was written in terms of clipping points and lines just because those clipping routines were already implemented. But yes, the code in graphics.c plot_filledcurves() finish_filled_curve() fill_missing_corners() and maybe also plot_betweencurves() is quite tangled, and could probably be entirely replaced by a polygon- clipping algorithm such as you suggest below. As a side benefit it would reduce the size of the code by ~500 lines. That would be a nice project for someone. Ethan > A well-known algorithm to clip a filled polygon is by Sutherland and > Hodgman. Some very ingenious implementations exist, e.g. > http://www.codeguru.com/Cpp/misc/misc/graphics/article.php/c8965/, but I > wrote a simple one, in Perl, with which I was able to clip my polygons > myself, before sending them to gnuplot. The advantage of my code is that > it is simple and very fast, but its disadvantage is that it needs to > store both the input and the output polygons, so it needs more memory > than more sophisticated solutions. Yet, with current memory prices, this > should not really be a problem anymore. My implementation is > specifically to clip to rectangular areas. > > I include my Perl program. Perhaps a gnuplot code guru is interested to > implement Sutherland/Hodgman clipping; if so, (s)he may find it useful > to have a look at my Perl program. > I myself cannot write C (easily), but I think conversion of Perl to C > code will not be a great challenge. The real challenge lies in adjusting > the code to gnuplot data structures. > -- Ethan A Merritt |