How can I find the Euclidean distance between moving points?

3 views (last 30 days)
I deployed number of random points with their speed and displacement, how can I make these point MOVING frequently each second,
since the Euclidean distance between these points is updated each time interval ( second) based on the coordinates of new positions ?
NumNode=2;ro=1000;center=[0 0];Initial_Direction = rand(NumNode, 1) * 2 *pi; v = 15/3.6; % [m/s] velocity of node
theta_Node=2*pi*(rand(NumNode,1));
g = 0.5 * ro + 0.5 * ro * rand(NumNode,1); % let the Nodes deployed away from the center of circle network layout
PosNode_x=center(1)+g.*cos(theta_Node); % Initial positions
PosNode_y=center(2)+g.*sin(theta_Node);
PosNode = [PosNode_x ,PosNode_y]
DX2 = [cos(Initial_Direction(:)) .* v,sin(Initial_Direction(:)) .* v]; % displacement of Node
PosNodeNew = PosNode + DX2; % New position of node without rotating
rotaion2 = [cosd(Initial_Direction), -sind(Initial_Direction); sind(Initial_Direction), cosd(Initial_Direction)]; % Rotation matrix to make the movement of node similar to move on arc
% Index approach to multiply different matrix dimensions
index=1:numel(PosNode);
xyRotated1 = rotaion2;
xyRotated1(index)= rotaion2(index).*PosNode(index); % rotated matrix multiply by position of node
index2 = 1:numel(DX2);
Newposss=xyRotated1;
NewPosss(index2) = xyRotated1(index2) + DX2(index2);
gg= NewPosss(index2); % New position of node with rotating on arc
figure(1)
scatter(PosDrone_x,PosDrone_x,'r+')
figure(2)
scatter(PosDroneNew(:,1),PosDroneNew(:,2),'b*')
figure (3)
scatter (xyRotated1(:,1),xyRotated1(:,2),'r.')
axis equal
figure (4)
scatter(NewPosss(1,:),NewPosss(1,:),'b*')
axis equal
  1 Comment
Jan
Jan on 9 Apr 2022
The question is not clear. The euclidean distance is determined by vecnorm of the difference between the point's coordinates. But which variables are meant? What is the relation between the code and your question?

Sign in to comment.

Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!