use strict; my @x = (0, 2, 4); my @y = (0, 2, 0); my $polygon =  { x=>\@x, y=>\@y }; my $point1 =  { x=>2, y=>1 }; my $point2 =  { x=>5, y=>5 }; my $point3 =  { x=>1, y=>1 }; sub min {     return $_[0] < $_[1] ? $_[0] : $_[1]; } sub max {     return $_[0] > $_[1] ? $_[0] : $_[1]; } sub isInside {     # return values: -1 == draussen, 0 == auf Kante , 1 == innerhalb    my $polygon = shift;    my $point = shift;    my $nPPoints = 0;           return -1 if(($nPPoints = scalar(@{$polygon->{x}})) != scalar(@{$polygon->{y}}));      return -1 unless $nPPoints;       my $x = $point->{x};    my $y = $point->{y};    my $ax = $polygon->{x}->[$nPPoints-1];    my $ay = $polygon->{y}->[$nPPoints-1];    my $lx = $ax;    my($bx, $by) = (0, 0);    my($count, $ignore, $zx) = (0, 0, 0);    for my $i (0..$nPPoints-1)    {       $bx = $polygon->{x}->[$i];       $by = $polygon->{y}->[$i];              if(!$ignore)       {          if($by == $y and $bx>=$x)          {             return 0 if $bx == $x;             $ignore = 1;          }          else          {             if(($ay < $y) == ($y < $by))             {                if($x < min($ax, $bx)) { $count++; }                elsif($x > max($ax, $bx)) {}                elsif($x < ($zx = (($bx-$ax)*($y-$ay)/($by-$ay))+$ax)) { $count++; }                elsif($zx == $x) { return 0; }                              }             $ax = $bx; $ay = $by;          }       }       else       {           if($by == $y)           {               return 0 if((($lx < $x) == ($x<$bx)) or $bx == $x);           }           else           {               $count++ if(($ay < $y) == ($y < $by));               $ignore = 0;               $ax = $bx; $ay = $by;           }                           }       $lx = $bx;    }           return ($count & 1) ? 1 : -1; } print "Point1: ", isInside($polygon, $point1),"\n"; print "Point2: ", isInside($polygon, $point2),"\n"; print "Point3: ", isInside($polygon, $point3),"\n";