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.)


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

In reply to Graphics math. by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.