# comp.graphics.algorithms

## Subject: Re: Plotting non overlapping rectangles

> I probably do not understand your post. Here is the
> posted. Perhaps I misunderstand what you mean by
> "center line" and by adding offsets to A and B.
>
> http://www.geometrictools.com/Temp/TouchingRectangles.png

Yes you understood my problem correctly. The width of the moveable rectangle
is variable and is most often smaller than the width of the fixed rectangle.
At first I wanted either the edge or the vertices of the moveable rectangle
to follow the outline of the fixed rectangle. However after knocking a
simple basic program together using your ideas I seem to like this way
better.

> Let V[i], 0 <= i <= 3, be the vertices of the fixed
> rectangle. Determine the index k for which
> Dot(D,V[k]-A) is a maximum. The vertex V[k] is
> an extreme vertex of the rectangle in the direction D.
> The point C = A + Dot(D,V[k]-A)*D.

My interpretation of Dot(D,V[k]-A) is:
((Bx - Ax) * (V[k].x - Ax)) + ((By - Ay) * (V[k].y - Ay))

However in order for things to work correctly I had to divide this by the
length of the line AB squared.

Many thanks

Steve