I make a square around/below a given point with given width (w) and length (l) like shown below

[![enter image description here](https://i.stack.imgur.com/t1TiC.jpg)](https://i.stack.imgur.com/t1TiC.jpg)

But now I have to induce the direction of the point (or heading so to say). I want to create a rectangle directed towards that direction like shown below. I have never worked with headings before, if anyone can point me in the right directions, that would be helpful.

[![enter image description here](https://i.stack.imgur.com/5dEFJ.jpg)](https://i.stack.imgur.com/5dEFJ.jpg)

-----------------EDIT---------------
Thank you @MBo & @HansHirse, I implemented as suggested by your people. for simplicity, I chose the point to be on the top line of the rectangle rather to be away from the rectangle. my code is as shown below:

```
% Point coordinates
P = [5; 5];

% Direction vector
d = [1; -5];

%normalizing 
Len = sqrt(d(1)*d(1)+d(2)*d(2));
cs = d(1)/Len;
sn = d(2)/Len;

% Dimensions of rectangle
l = 200;
w = 100;

% Original corner points of rectangle

x1 = P(1) -w/2;
y1 = P(2);
x2 = P(1)+ w/2;
y2 = P(2);
x3 = P(1)+ w/2;
y3 = P(2) - l;
x4 = P(1) -w/2;
y4 = P(2) - l;
rect = [x1 x2 x3 x4; y1 y2 y3 y4];

%rotated rectangles coordinates:
x1_new = P(1)+ (x1 - P(1))* cs - (y1 - P(2))*sn;
y1_new = P(2) +(x1-P(1))*sn + (y1-P(2))*cs;
x2_new = P(1)+ (x2 - P(1))* cs - (y2 - P(2))*sn;
y2_new = P(2) +(x2-P(1))*sn + (y2-P(2))*cs;
x3_new = P(1)+ (x3 - P(1))* cs - (y3 - P(2))*sn;
y3_new = P(2) +(x3-P(1))*sn + (y3-P(2))*cs;
x4_new = P(1)+ (x4 - P(1))* cs - (y4 - P(2))*sn;
y4_new = P(2) +(x4-P(1))*sn + (y4-P(2))*cs;
new_rect = [x1_new x2_new x3_new x4_new; y1_new y2_new y3_new y4_new];

%plot:
figure(1);
plot(P(1), P(2), 'k.', 'MarkerSize', 21);  
hold on;
plot([P(1) P(1)+d(1)*10], [P(2) P(2)+d(2)*10], 'b');
patch(new_rect(1,:),new_rect(2,:), 'b', 'FaceAlpha', 0.2);
patch(rect(1,:),rect(2,:),'b')
hold off

```

The way it is rotating is not what I wanted: I am not able to upload a pic, imgur is acting weird. You can run the exact code, you will get the output I am getting.