my @slope = (($ne[1]-$nw[1])/($ne[0]-$nw[0]), ($se[1]-$sw[1])/($se[0]-$sw[0]), ($se[0]-$ne[0])/($se[1]-$ne[1]), ($sw[0]-$nw[0])/($sw[1]-$nw[1])); my @start = ($ne[1]-$ne[0]*$slope[0], $se[1]-$se[0]*$slope[1], $nw[0]-$nw[1]*$slope[2], $ne[0]-$ne[1]*$slope[3]); my $in_quad = $find[0]*$slope[0]+$start[0]>=$find[1] and $find[0]*$slope[1]+$start[1]<=$find[1] and $find[1]*$slope[2]+$start[2]>=$find[0] and $find[1]*$slope[3]+$start[3]<=$find[0];

I've only checked this in my head -- hope it helps. It's easy to bomb this for slopes that divide by zero, but you can easily check for that. You can also put that last line in a loop if you would like, but I think this is cleaner.

Anyway, back to work,
Gryn

Update: Just incase you're wondering, you should be able to avoid the divided by zero's by multiply'ing each subexpression by the appropriate divided term. That is, in case my current code is actually correct, change the first condition to:
$find[0]*$slopetop[0]+$start[0]>=$find[1]*$slopebot[0] And the def of $start[0] changes to:
$ne[1]*$slopebot[0]-$ne[0]*$slopetop[0]

(@slopetop and @slopebot are now the top and bottom parts of @slope of course).

Ok, honest... back to work :)


In reply to Re: Better Logic? by gryng
in thread Better Logic? by orbital

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.