Download (as "arc.pm") arc.pm
# -*- code: utf-8 -*-
package arc;
my($VERSION);
$VERSION = "2018-09-07 11:40" ; # written by emacs time-stamp
use POSIX qw(floor ceil);
sub arc($$$$ $$$$){
my ($x) = shift; # center coordinate x
my ($y) = shift; # center coordinate y
my ($start_angle) = shift; # in degree
my ($end_angle) = shift; # in degree
my ($radius) = shift; # in micron
my ($polygon_count) = shift; # default 12;
my ($ROUND) = shift; # round to this unit ( making not smooth line);
my ($direction) = shift; # -1 counter clockwise, 1 clockwise
if ($polygon_count eq '') { $polygon_count = 12;}
my (@PTR);
if ($end_angle < $start_angle && $direction > 0) { $end_angle += 360;}
if ($end_angle == 0 && $start_angle == 0 ) { $start_angle = 0; $end_angle = 360;}
my ($step) =
($end_angle - $start_angle)/$polygon_count;
my ($count) = ceil((abs($end_angle - $start_angle))/$step);
my ($prevX, $prevY);
foreach my $i (0 .. $count ){
my $radian = ($start_angle + $i * $step) * 3.1415926535/180;
my ($X) = $x + $radius * cos($radian);
my ($Y) = $y + $radius * sin($radian);
push(@PTR, [ $X, $Y]);
}
if ($direction < 0 ){ @PTR = reverse @PTR ;}
my @COORDS;
foreach my $i (0 .. $count){
push(@COORDS, ($PTR[$i]->[0],
$PTR[$i]->[1] ) );
}
# print join ("\n", @COORDS). "\n";
return @COORDS
}
1;
|