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
2015년 12월 21일
댓글 수: 8
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?

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).
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.

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')
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.
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.
Thanks for your guidance.
My pleasure.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
