*--------------------*
\ A /
* *-----* /
/ \ \ /
/ \ \ /
*--------* \ /
*
####
*--------------------*
\ A /
*--*-----*-------*
/ \ \ A(3)/
/ A(2) \ \ /
*--------* \ /
*
##
##
sub _pointIsInQuadrilateral {
my ($a_point, $a_x, $a_y) = @_;
# point coords
my ($x, $y) = ($a_point->[0], $a_point->[1]);
# poly coords
# $n is the number of points in polygon.
my @x = @$a_x; # Even indices: x-coordinates.
my @y = @$a_y; # Odd indices: y-coordinates.
if ($x < ($x[1]-$x[0]) * ($y-$y[0]) / ($y[1]-$y[0] + $x[0]) ) {
# $x is left of the leftmost edge, so it's not in polygon
return 0;
}
if ($x < ($x[3]-$x[2]) * ($y-$y[2]) / ($y[3]-$y[2] + $x[2]) ) {
# $x is right of the rightmost edge, so it's not in polygon
return 0;
}
# Point is inside quadrilateral!
return 1;
}