in reply to Re: Clockwise or Counter-clockwise
in thread Clockwise or Counter-clockwise
I tested a self-crossing unit "cube" in the input instead of a straight one, and got the result "0". This refutes my idea that self-crossing polygons will work with this algorithm.sub direction{ local $_; my (@poly) = @_; push @poly, $poly[0]; $_ += $a->[0] * $b->[1] - $a->[1] * $b->[0] while ($a,$b)=(shift @poly,$poly[0]), @poly; print "result is $_\n"; $_ < 0; } my @unitCubeAnti = ([0,1],[1,1],[0,0],[1,0]); print direction(@unitCubeAnti) ? 'Anticlockwise' : 'Clockwise'; print "\n"; my @unitCubeClock = reverse @unitCubeAnti; print direction(@unitCubeClock) ? 'Anticlockwise' : 'Clockwise'; print "\n";
|
|---|