Thread Übergeben von 3 arrayreferenzen beim Fktaufruf
(7 answers)
Opened by ariser at 2016-09-16 15:41
Hier wäre ein lauffähiges Beispiel:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 #!c:\strawberry\perl\bin\perl.exe -w use diagnostics; use autodie; use Data::Dumper; use Getopt::Long; # We process long commandline options, better to read, longer time to think over it. use Config::Tiny; # simple configurations use Math::Polygon::Calc; use CAD::Calc; use strict; print "huhu\n"; #my $poly = Math::Polygon->new( [0, 0], [3, 2], [2, 3.5], [0.5, 6], [0, 8], [-0.5, 6], [-2, 3.5], [-3, 2], [0, 0]); my @apoly = ( [0, 0], [3, 2], [2, 3.5], [0.5, 6], [0, 8], [-0.5, 6], [-2, 3.5], [-3, 2], [0, 0]); my $bpoly=\@apoly; print "\n"; if (checkforoffset($bpoly,[0,1],0.1)) { print "1,1: drin\n"; } else { print "1,1: draußen\n"; } exit 0; sub checkforoffset { my $pref=shift; my $pt=shift; my $dist=shift; print "checkforoffset called:\n"; print Dumper($pref); for (my $idx=1; $idx < scalar(@$pref); ++$idx) { my $ldist=getdistance($pref->[$idx-1], $pref->[$idx], $pt); print "dist $ldist \n"; if ($dist >= $ldist) { return (1==0); } } return (1==1); } sub getdistance { print "getdistance called:\n"; print Dumper(\@_); my ($p0,$p1,$pt)=shift; print Dumper($p0); print Dumper($p1); print Dumper($pt); my $vx=$p1->[0]-$p0->[0]; my $vy=$p1->[1]-$p0->[0]; print "$vx $vy \n"; return ( abs($vy*$pt->[0] - $vx*$pt->[1] + $p1->[0]*$p0->[1] - $p1->[1]*$p0->[0]) / sqrt($vy**2 + $vx**2) ); } und die von Dir vorgeschlagene Variante funktioniert! Jetzt wüsste ich gerne trotzdem noch, warum meine Variante Schrott ist. |