#package bitcreator; use strict; use Data::Dumper; $Data::Dumper::Terse = 1; $Data::Dumper::Indent = 1; $Data::Dumper::Sortkeys = sub { my @keys = sort {$a cmp $b} keys %{@_}; return \@keys; }; #sub bitcreator { my $h = {};#shift; $h->{0}{X1} = 0; $h->{0}{Y1} = 0; $h->{1}{X1} = 6; $h->{1}{Y1} = 4; my @stream; # cuttingmaschine 34 cm = 32000 steps on each motor (x,y) my @keys = sort { my $x = $a; $x ||= 0; my $y = $b; $y ||= 0; $x <=> $y} keys %{$h}; for my $a(1..$#keys){ my $xbefore = $h->{$a-1}{X1}; my $ybefore = $h->{$a-1}{Y1}; my $x = $h->{$a}{X1}; my $y = $h->{$a}{Y1}; my $distx = ($x - $xbefore) #realer Wert in cm my $disty = ($y - $ybefore) #realer Wert in cm # y = m * x + t my $m = ($ybefore - $y) / ($xbefore - $x); my $t = $y - ($x * $m); my $anzxsteps = sprintf("%0.f",($distx ));#* (32000/34))); my $anzysteps = sprintf("%0.f",($disty ));#* (32000/34))); my $stepsizeX = $distx / $anzxsteps; my $stepsizeY = $disty / $anzysteps; if ($anzxsteps >= $anzysteps){ my $Xbit = 1; for my $b (1..$anzxsteps){ my $Ybit = 0; my $y1 = $m * ($b*$stepsizeX) + $t; if (sprintf("%0.f",$y1 / $stepsizeY) >= $y1) {$Ybit = 1;} push @stream,$Xbit,$Ybit; }#end for $b }#end if else{ my $Ybit = 1; for my $b (1..$anzysteps){ my $Xbit = 0; my $x1 = (($b*$stepsizeY) - $t) / $m; if (sprintf("%0.f",$x / $stepsizeX) >= $x1) {$Xbit = 1;} push @stream,$Xbit,$Ybit; }#end for $b }#end else }#end for $a print "@stream\n"; #} # end sub #1;