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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |