use GD; my $size=500; my $scale=20; my $yinvert=-1; my ($xcenter,$ycenter)=(19.5,-5); my $i = new GD::Image($size,$size); $white = $i->colorAllocate(255,255,255); $black = $i->colorAllocate(0,0,0); $blue = $i->colorAllocate(0,0,255); $dred = $i->colorAllocate(128,0,0); $bred = $i->colorAllocate(255,0,0); $green = $i->colorAllocate(0,255,0); sub scaled # scale distances { my (@xyus)=@_; # unscaled xy pairs or distances. my @xys; # scaled xy pairs while (@xyus) { my $x=$xyus[0]; push(@xys, $x*$size/$scale); shift(@xyus); } return (@xys); } sub scale { my (@xyus)=@_; # unscaled xy pairs or distances. my @xys; # scaled xy pairs while (@xyus) { my $x=$xyus[0]-$xcenter; my $y=$xyus[1]-$ycenter*$yinvert; push(@xys, $x*$size/$scale+$size/2,$y*$size/$scale*$yinvert+$size/2); shift(@xyus); shift(@xyus); } return (@xys); } # first draw some radial lines at 0.25 degree intervals. # the lines are 1 unit long and centered at the point 20,0. my $pi=4.0 * atan2(1, 1); my $rad=$pi/180.0; # to radions convert factor my $deg=180.0/$pi; # to degrees convert factor. my $v1=19; # vector lengths of lines being drawn from v1 to v2. my $v2=21; my $astep=10; my $oldangle; for my $j (0..4) { my $angle=$astep*$j; my $startx=$v1*cos($angle*$rad); my $starty=$v1*sin($angle*$rad); my $endx=$v2*cos($angle*$rad); my $endy=$v2*sin($angle*$rad); $i->line(scale($startx,$starty,$endx,$endy),$blue); # radial lines # now we draw some arcs, always 1 degree long, but starting at steps of 0.1 degree # we draw the lowest arc nearest the center, ie 1 to 2 deg, then 1.1 to 2.1 deg further out and so on. # angles are clockwise, and our +ve direction is acw, so in fact we start at # 359 to 360, then further out 359.1 to 360.1, and so on for my $k (0..10) { my $kstep=1; my $kmove=0.2; $i->arc(scale(0,0),scaled(2*$v1+$k*$kmove,2*$v1+$k*$kmove),360-$angle-$k*$kstep,360-$oldangle-$k*$kstep,$bred) if ($j%8==1); } $oldangle=$angle; } my $file="gdbug1.png"; open(F,">".$file) or die "Cannot open file ".$file; binmode F; print F $i->png; close F; #### use GD; my $size=500; my $scale=4.5; my $yinvert=-1; my ($xcenter,$ycenter)=(19.5,-1.5); my $i = new GD::Image($size,$size); $white = $i->colorAllocate(255,255,255); $black = $i->colorAllocate(0,0,0); $blue = $i->colorAllocate(0,0,255); $dred = $i->colorAllocate(128,0,0); $bred = $i->colorAllocate(255,0,0); $green = $i->colorAllocate(0,255,0); sub scaled # scale distances { my (@xyus)=@_; # unscaled xy pairs or distances. my @xys; # scaled xy pairs while (@xyus) { my $x=$xyus[0]; push(@xys, $x*$size/$scale); shift(@xyus); } return (@xys); } sub scale { my (@xyus)=@_; # unscaled xy pairs or distances. my @xys; # scaled xy pairs while (@xyus) { my $x=$xyus[0]-$xcenter; my $y=$xyus[1]-$ycenter*$yinvert; push(@xys, $x*$size/$scale+$size/2,$y*$size/$scale*$yinvert+$size/2); shift(@xyus); shift(@xyus); } return (@xys); } # first draw some radial lines at 0.25 degree intervals. # the lines are 1 unit long and centered at the point 20,0. my $pi=4.0 * atan2(1, 1); my $rad=$pi/180.0; # to radions convert factor my $deg=180.0/$pi; # to degrees convert factor. my $v1=19; # vector lengths of lines being drawn from v1 to v2. my $v2=20; my $astep=1; my $oldangle; for my $j (0..7) { my $angle=$astep*$j; my $startx=$v1*cos($angle*$rad); my $starty=$v1*sin($angle*$rad); my $endx=$v2*cos($angle*$rad); my $endy=$v2*sin($angle*$rad); $i->line(scale($startx,$starty,$endx,$endy),$blue); # radial lines # now we draw some arcs, always 1 degree long, but starting at steps of 0.1 degree # we draw the lowest arc nearest the center, ie 1 to 2 deg, then 1.1 to 2.1 deg further out and so on. # angles are clockwise, and our +ve direction is acw, so in fact we start at # 359 to 360, then further out 359.1 to 360.1, and so on for my $k (0..20) { my $kstep=0.1; my $kmove=0.1; $i->arc(scale(0,0),scaled(2*$v1+$k*$kmove,2*$v1+$k*$kmove),360-$angle-$k*$kstep,360-$oldangle-$k*$kstep,$bred) if ($j%8==1); } $oldangle=$angle; } my $file="gdbug2.png"; open(F,">".$file) or die "Cannot open file ".$file; binmode F; print F $i->png; close F;