# Calculate 'Rectangle' Coordinates Given 2 Points and width

I want to create a rectangular polygon using two points as guides.

So let's say a journey starts in Egypt and ends in London, my polygon should have 4 points:

• 10 miles further from London than Egypt is, following the line between them (roughly south in this example).
• Halfway between the two cities but 50 miles at right angles from the line that joins them.
• Like the above point but 50 miles in the other direction.
• 20 miles further from Egypt than London is, following the line between them (roughly north in this example).

I'll end up with a rough diamond shaped polygon that would completely contain the straight line journey from Egypt to London.

I hope this makes sense; any help for how I can calculate the 4 points is appreciated.

I have also asked this on gis.stackexchange.com but as I only need 2D and the fact that its map coordinates is irrelevant. I thought I would ask it here as well.

EDIT:

Thanks to Ju'x i have come a long way, but the outer points dont seem to be at 90 degrees to the mid point (image here: http://i.stack.imgur.com/lxX9l.png). I am pretty sure i have followed the answer given correctly....

-

Let's say $L$ with coordinates $(x_L;y_L)$ stands for London, and $C$ with coordinates $(x_C; y_C)$ stands for Cairo (Egypt is hardly a point on a map). I will assume that the coordinates are expressed in miles, so that (for example) $$LC = \sqrt{(x_C-x_L)^2 + (y_L - y_c)^2}$$ is the distance between London and Cairo in miles.
The unit vector $u = \dfrac{\overrightarrow{LC}}{\left\|\overrightarrow{LC}\right\|}$ has coordinates $\left(\dfrac{x_C-x_L}{LC},\dfrac{y_C-y_L}{LC}\right) = \left(x_u,y_u\right)$.
The two extremal points of your polygon are $C' = C + 10u$ and $L' = L - 20u$ : $$C' = \left(x_C + 10x_u,y_c + 10y_u\right)\qquad L' = \left(x_L - 20x_u, y_L - 20y_u\right)$$
The midpoint $M$ has coordinates $(x_M,y_M)=\left(\dfrac{x_C+x_L}{2},\dfrac{y_C+y_L}{2}\right)$, and an orthogonal vector to $u$ is the unit vector $v$ with coordinates $(x_v,y_v) = (y_u, -x_u)$. The two lateral points of your polygon are $A = M + 50v$ and $B = M - 50v$ : $$A = \left(x_M + 50x_v, y_M + 50 y_v\right),\qquad B = \left(x_M - 50x_v, y_M - 50y_v\right).$$
You should check $v$: if $u = (a,b)$ then take $v=(b, -a)$. –  Siméon Jan 16 '13 at 13:56