Subject: | GD::Simple->arc() start and end angles are incorrect |
Version: there is none, there is only a single release in CPAN dated 2004
Problem:
Calling $img->arc($width,$height,$start_angle,$end_angle); should draw
an ellipse from $start_angle to $end_angle (angles in degrees). However,
this only works properly if the width and height are the same - i.e. you
are drawing part of a circle. If the shape is elliptical, the angles
that the arc starts and end at are not the ones specified in the arguments.
Thus: $img->arc(300,200,240,120); should draw an arc from 240 degrees to
120 degress. It doesn't. The start angle is more like 230 degrees and
the end angle is approximately 130 degrees - measured from the "centre"
of the ellipse, the point "moveTo'd" before the call to arc()
See the included demo file for a graphic illustration of this mistake.
Subject: | ptest.pl |
#!/usr/bin/perl
use GD::Simple;
$PI=3.141526;
$RADIAN=360/(2*$PI);
$img = GD::Simple->new(800,800);
$img->fgcolor('gray');
$img->bgcolor(undef);
for $i (100, 200, 300, 400, 500, 600, 700) { $img->moveTo(0,$i); $img->lineTo(799,$i); }
for $i (100, 200, 300, 400, 500, 600, 700) { $img->moveTo($i,0); $img->lineTo($i,799); }
$img->rectangle(0,0,799,799);
# draw basic circle
$img->moveTo(400,400); $img->ellipse(600,600);
$img->fgcolor('black');
#label outside of circle
for ($i=0; $i < 360;$i+=(360/24)) {
$n = ($i+90) / $RADIAN;
$x = 300 * sin $n;
$y = 300 * cos $n;
$img->moveTo(400+$x, 400-$y); $img->string($i); # N.B. the "string" changes the origin
$img->moveTo(400+$x, 400-$y); $img->lineTo(400,400); # so we have to go back there
}
# plot an arc
$img->moveTo(400,400); $img->fgcolor('green'); $img->arc(500,500,60,300);
$img->moveTo(400,400); $img->fgcolor('green'); $img->arc(490,490,60,280);
$img->moveTo(400,400); $img->fgcolor('green'); $img->arc(480,480,60,240);
$img->moveTo(400,400); $img->fgcolor('green'); $img->arc(470,470,60,180);
$img->moveTo(400,400); $img->fgcolor('blue'); $img->arc(300,200,240,120);
$img->moveTo(400,400); $img->fgcolor('blue'); $img->arc(290,190,210,120);
$img->moveTo(400,400); $img->fgcolor('blue'); $img->arc(280,180,180,120);
$img->moveTo(400,400); $img->fgcolor('blue'); $img->arc(270,170,150,120);
$img->moveTo(400,400); $img->fgcolor('red'); $img->arc(400,400,240,120);
$img->moveTo(400,400); $img->fgcolor('red'); $img->arc(390,390,210,120);
$img->moveTo(400,400); $img->fgcolor('red'); $img->arc(380,380,180,120);
$img->moveTo(400,400); $img->fgcolor('red'); $img->arc(370,370,150,120);
print $img->png;