Of course it’s possible. Here’s a sketchy account, if you need more details let me know. Just a word of warning, I’m writing this off the top of my head without actually trying it out, so I will probably make some silly mistakes you’ll need to correct 🙂
Let’s say the center of your rectangle is at (xc, yc). Since you want to move the rectangle, just make those parameters controllable by sliders. Also, suppose the rectangle has width w and height h (if you wish, you could even make controls for these, so you can stretch and resize). You have a slider controlling an angle we’ll call th, and finally a slider for the “time” t; as you move t from 0 to 1 your bug will crawl along the perimeter of the rectangle. The 0-1 range is just for convenience, of course; you can choose whatever you like.
Define variables x0, y0 and set them as follows:
if t<=0.25 then x0 = xc-w/2, y0 = yc+h/2-4*h*t;
if t>0.25 and t<=0.5 then x0 = xc-w/2+4*w*(t-0.25), y0 = yc-h/2;
if t>0.5 and t<=0.75 then x0=xc+w/2, y0=yc-h/2+4*h*(t-0.5);
if t>0.75 then x0=xc+w/2-4*w*(t-0.75), y0=yc+h/2;
So far, x0 and y0 indicate the location of the ant ignoring the rotation. Finally we need to rotate. I’m assuming the rotation is about the center (xc, yc) of the rectangle, wherever it is as the moment; in principle you can rotate about other points but I don’t think this is what you’re after.
So…
x1 = xc + (x0-xc)*cos(th) + (y0-yc)*sin(th);
y1 = yc – (x0-xc)*sin(th) + (y0-yc)*cos(th);
And that’s it: (x1, y1) is where the ant needs to be.
If you’re familiar with AE expressions and controls you should be able to use these formulas to make your ant. Good luck,
– A. A.