Plot a line between two points with given angle which points its direction.

I need your guidance that how I can compute angle between two points and draw a direction vector to get the direction of these two colored lines(Pink,Blue) at each instant of time.
Secondly is it possible that I can extract the speed as I am given (x,Y) position and time (as can be seen from the figure which is plotted on X,Y plane in a given time)?
Thanks in advance for your kind reply.

 採用された回答

Star Strider
Star Strider 2015 年 12 月 21 日

0 投票

8 件のコメント

Arsal15
Arsal15 2016 年 1 月 20 日
Using quiver I have got this graph, using quiver [x,y,u,v] and i know the x and y position of start and end of direction vector for a node but how I can get the value of node position in the middle of a vector. It will be (x2-x1/u,y2-y1/v) or something different?
Star Strider
Star Strider 2016 年 1 月 20 日
I don’t know what you mean by ‘the value of node position in the middle of a vector’. You would have to know one value (either x or y) to get the other. If you have two specific (x,y) points and you want an equation for a line connecting them, the easiest way would be to use the polyfit and polyval functions and the known x-value between them:
b = polyfit([x1, x2], [y1, y2], 1);
y3 = polyval(b, x3);
such that ‘x3 here is between ‘x1’ and ‘x2’ (that is, x1 < x3 < x2).
Arsal15
Arsal15 2016 年 1 月 21 日
編集済み: Arsal15 2016 年 1 月 21 日
Star Strider, Thanks for your kind reply.
I have attached my code file so you will better get idea about my code. I want to find the position of a node at any instant of time when i just run this simulation it give me minimum distance from other node and its own position at that time instant.
Star Strider
Star Strider 2016 年 1 月 21 日
You have four variables each (1x501) vectors. Your time variable is a (7x1) double, so doing anything with respect to that time vector is not going to work. You could get time from the position differences and the velocities, but I am lost as to what you want to do. Plotting ‘v_x’ and ‘v_y’ is straightforward and produces 5 straight lines.
I have no idea what you want to do, but I took a wild guess and came up with this:
D = load('Arsal15 node_property.mat');
np = D.node_property;
x = np.v_x;
y = np.v_y;
vx = np.vel_x;
vy = np.vel_y;
xp = gradient(x); % X-Position Change
yp = gradient(y); % Y-Position Change
vt = hypot(vx(:), vy(:)); % Net Velocity
pt = hypot(xp, yp); % Net Position Change
tv = pt(:)./vt(:); % Differential Time
tc = cumsum(tv); % Cumulative Time
figure(1)
plot3(x, y, tc, '-r')
hold on
quiver3(x(:), y(:), tc(:), xp(:), yp(:), tv(:), 1.5, 'LineWidth',1)
hold off
grid on
xlabel('X')
ylabel('Y')
zlabel('Time')
figure(2)
plot3(x, y, tc, '.r')
hold on
quiver3(x(:), y(:), tc(:), xp(:), yp(:), tv(:), 2.5, 'LineWidth',1)
hold off
grid on
xlabel('X')
ylabel('Y')
zlabel('Time')
Arsal15
Arsal15 2016 年 1 月 21 日
Thanks for your time and kind reply Star Strider.
Actually I want to do three things
Regarding time I can use interpolation like this so all index will be (1x51).
if true
node_property(nodeIndex).time = interp1(s_mobility.VS_NODE(nodeIndex).V_TIME,v_t);
end
1) .Getting data from the structure in a efficient way so that I use one loop index and I get data of all mobile nodes in their variable like x_position, y_position x_velocity, y_velocity using single for loop.
2). I want the position of mobile node at any instant of time like if I call a function
if true
[x,y] = node_position(node_number,time_instant,direction);
end
it gives times position of that node at that time instant but also direction vector value.
3). I want to calculated distance of node1(x,y) with node2(x,y) I am using function
if true
distance = findSqDistance(node1_X,node1_Y,node2_X,node2_Y);
end
but I am fail to pass array of (1x51) of x and y of node1 and node 2 to this function and get a result back in distance matrix which also a (1x51) so I m stuck. Actually i get puzzled in indexing.
Star Strider
Star Strider 2016 年 1 月 21 日
My pleasure.
I have no idea what you’re doing. I gave my best guess, and that’s all I can do. Your ‘nodes’ simply look like points on the trajectory of something, and beyond plotting them as I did, I really cannot help further.
Arsal15
Arsal15 2016 年 1 月 24 日
Thanks for your guidance.
Star Strider
Star Strider 2016 年 1 月 24 日
My pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

タグ

質問済み:

2015 年 12 月 21 日

コメント済み:

2016 年 1 月 24 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by