How to position images using Polar coordination (in a circle

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?".
Post Reply
janjaap

How to position images using Polar coordination (in a circle

Post by janjaap »

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

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to position images using Polar coordination (in a circle

Post by fmw42 »

(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

Re: How to position images using Polar coordination (in a circle

Post by janjaap »

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

Re: How to position images using Polar coordination (in a circle

Post by janjaap »

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));
Post Reply