Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
janjaap
Post
by janjaap » 2008-03-10T15:25:15-07:00
Dear ImageMagick Experts,
I was wondering if anyone could help me to be able to position an animated gif (dot) in a circle using Polar coordination so that I am able to use bearing (degrees) and distance to the edge as values to determ the position of the dot.
My current code is the folowing (PHP):
Code: Select all
exec("convert -size 38x38 ./images/compass_38.gif -font ./fonts/hotlink_watermark.ttf -pointsize 9 -draw \"text 26,32 '".$distance_limit."'\" -background '#F6F4F0' \( ./images/flashing_star_10.gif -repage 0x0+".$x."+".$y."\! \) -loop 0 -crop 34x30+4+4\! ./images/result.gif;");
More information about the polar coordinate system:
http://en.wikipedia.org/wiki/Polar_coordinate_system
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 2008-03-10T16:07:55-07:00
(x-xc)=r*cos(pi*angle/180)
(y-yc)=r*sin(pi*angle/180)
where
xc=x coordinate of center of image
yc=y coordinate of center of image
r=radius
angle=bearing in degrees
janjaap
Post
by janjaap » 2008-03-10T16:20:03-07:00
Hi there!
Thanks a lot for your reply.
Do you happen to know how to do this calculation in PHP? The folowing doesn't work:
Code: Select all
$x = 14*cos(pi()*$prikker["bearing"]/180);
$y = 14*sin(pi()*$prikker["bearing"]/180);
$x = $x - 14;
$y = $y - 14;
janjaap
Post
by janjaap » 2008-03-10T17:25:43-07:00
I found the solution via Experts Exchange:
$x_z = 14;
$y_z = 14;
$R = $distance_limit;
$d = round($prikker["distance"]); // 5.5; //
$b = round($prikker["bearing"]); // 75; //
$_r = $R - $d;
$theta = 90 - $b;
$degrees = 90 - $b;
$radians = $degrees * pi() / 180;
$x = $x_z + (14 * (($R - $d) / $R) * cos($radians));
$y = $y_z - (14 * (($R - $d) / $R) * sin($radians));
$x = $x_z + (14 * ($d / $R) * cos($radians));
$y = $y_z - (14 * ($d / $R) * sin($radians));