BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:
These questions are mostly intellectual curiosity rather than an immediate requirement; and possibly off topic, though the code below is taken from one of my programs that is under active development.
I have a clip region defined in terms of several partially overlapping ellipses.
I tried to draw a picture, but it defeated my ascii art skills, but think the interior space of the Olympic Rings and wanting to only show (or exclude) those pixels that fall within (or outside) the combined perimeter.
And for generality -- and because the formula isn't much more complex -- define the rings as ellipses rather than circles. So the individual components of the region are stored as:
my @clips = ( { cx => $X * 0.500, cy => $Y * 0.4, rx2 => ( $X * 0.295 )**2, ry +2 => ( $Y * 0.40 )**2 }, { cx => $X * 0.500, cy => $Y * 0.6, rx2 => ( $X * 0.390 )**2, ry +2 => ( $Y * 0.34 )**2 }, { cx => $X * 0.428, cy => $Y * 0.748, rx2 => ( $X * 0.067 )**2, ry +2 => ( $Y * 0.038)**2 }, ... };
So I have code that does something like:
sub clip { my( $x, $y ) = @_; return 1 if ( $x - $clips[0]{cx} )**2 / $clips[0]{rx2} + ( $y - $c +lips[0]{cy} )**2 / $clips[0]{ry2} < 1; return 1 if ( $x - $clips[1]{cx} )**2 / $clips[1]{rx2} + ( $y - $c +lips[1]{cy} )**2 / $clips[1]{ry2} < 1; return 1 if ( $x - $clips[2]{cx} )**2 / $clips[2]{rx2} + ( $y - $c +lips[2]{cy} )**2 / $clips[2]{ry2} < 1; ... return 0; }
If the point is within any of the rings, return true (draw it), otherwise return false (don't).
Without resorting to rasterising the whole thing, which requires more tests; more space and doesn't work with scaling, is there any (simple) way to combine the formulae of the ellipses that would result in less tests?
On a related, but probably fanciful note, imagine I was only interested in seeing the region of the interior that lies within half a minor axis of the perimeter of the combined region, can that be defined parametrically?
And finally, if I wanted to split the entire perimeter at one point, stretch it out to a straight horizontal line, and display the half minor axis region, above that line, what on earth would the transform look like?
(Some distortion would be involved -- similar to the poles under Mercator Projection -- but that is okay.)
|
---|
Replies are listed 'Best First'. | |
---|---|
pixel in ellipsis:
by FreeBeerReekingMonk (Deacon) on Jun 03, 2015 at 18:37 UTC | |
by BrowserUk (Patriarch) on Jun 03, 2015 at 19:10 UTC | |
by roboticus (Chancellor) on Jun 03, 2015 at 23:02 UTC | |
by BrowserUk (Patriarch) on Jun 04, 2015 at 14:43 UTC | |
by FreeBeerReekingMonk (Deacon) on Jun 03, 2015 at 20:31 UTC | |
Re: Graphics math.
by MidLifeXis (Monsignor) on Jun 03, 2015 at 17:43 UTC | |
by BrowserUk (Patriarch) on Jun 03, 2015 at 18:14 UTC | |
Re: Graphics math.
by Limbic~Region (Chancellor) on Jun 04, 2015 at 14:55 UTC | |
by BrowserUk (Patriarch) on Jun 04, 2015 at 15:48 UTC | |
by Limbic~Region (Chancellor) on Jun 04, 2015 at 16:14 UTC | |
by BrowserUk (Patriarch) on Jun 04, 2015 at 16:24 UTC | |
Re: Graphics math.
by Anonymous Monk on Jun 04, 2015 at 08:52 UTC | |
by BrowserUk (Patriarch) on Jun 04, 2015 at 12:43 UTC |