The sine and cosine of t are respectively the y and x coordinate of a point on the circle forming an angle t with the x-axis. No need for that in a rectangle! A rectangle is made of four lines. If t
goes from 0
to 1
, it reach the point (px,py)
at t==0
and to (qx,qy)
at t==1
with the line given by:
(l(x),l(y)) = (t*qx + (1-t)*px, t*qy + (1-t)*py)
if instead of 0
and 1
, you time goes from t0
to t1
, you can normalize the time first and then apply the above formula.
(l(x),l(y)) = ( ((t-t0)/(t1-t0))*qx + ((t1-t)/(t1-t0))*px, ((t-t0)/(t1-t0))*qy + ((t1-t)/(t1-t0))*py )
Now, for you rectangle, divide in four cases with an if
for each edge that covers one of the span of time and apply a line movement.
Notice that if your rectangle is axis-aligned, you will always have either the x-value or the y value which is constant. For instance, for t between 0
and a/4
(and supposing (X,Y) is bottom left),
(l(x),l(y)) = ((4*t/a)*(X+Width) + (1-4*t/a)*(X), Y+Height)
Which is also equals to:
(l(x),l(y)) = (X + (1-4*t/a)*(Width), Y+Height)