How to move random point on an arc by matlab

I deployed 2 nodes randomly by Binomial point process and
I wanted to move them on arc for specific distance then keep moving on straight line for specific distance and so forth, instead of Only move these nodes in straight lines.
given the turingangle of arc, length of arc, speed, acceleration of that node
could someone help me with that by using Matlab ? or advice me if this can be achieved by using Matlab and how ?
thanks in adance

 Accepted Answer

Take your two points, and the angle you want to rotate them by, and construct the rotation matrix
r = [cosd(theta), -sind(theta); sind(theta), cosd(theta)];
Then multiply your x,y to get the rotated xy
x = 5;
y = 0
plot([0, x], [0, y], 'b.-', 'MarkerSize', 50, 'LineWidth', 3)
grid on;
% Construct rotation matrix
theta = 25;
r = [cosd(theta), -sind(theta); sind(theta), cosd(theta)];
% Then multiply your x,y to get the rotated xy
xyRotated = r * [x; y];
xr = xyRotated(1);
yr = xyRotated(2);
hold on
plot([0. xr], [0, yr], 'r*-', 'MarkerSize', 30, 'LineWidth', 3)
axis equal; % Need equal so the angle is not squashed.

9 Comments

Thanks for your reply,
If I deployed the nodes randomly as demonstrated below how can I apply your code ? I would apreciate if you could help me with that.
ro=500; % radius of the layout circle
NumPoints=10; % Number of points
center=[0 0]; % center of the circle
theta_Points=2*pi*(rand(NumPoints,1)); % distributed random number of nodes
g = 0.5 * ro + 0.5 * ro * rand(NumPoints,1); % try to distance the points from the center
PosPoints_x=center(1)+g.*cos(theta_Points);
PosPoints_y=center(2)+g.*sin(theta_Points);
% Initial plot objects
hfig = figure('Color', 'w');
hax=axes('parent',hfig);
% Plot of deploying points
hdots=plot(PosPoints_x(:,1),PosPoints_y(:,1),'bp','MarkerSize', 12);
grid on
hold(hax, 'on')
axis(hax, 'equal')
% Plot the layout as circles
t = linspace(0, 2*pi);
plot(ro * cos(t) + center(1),ro * sin(t) + center(2))
if r given % r is the raduis of arc circle that nodes will be moving along that arc
theta given % which is the turning angle of the node as you assumed 25 degree
What do you want to do here?
According to my algorithm, I deplyed these nodes randomly and I want to move them each second either on arc of circle OR let them keep moving in straight line (repeat that procedure). please if you dont get my point I 'll explain it more and thank you for your response
the purpose of let them move on arc and let them change the direction to prevent the coalition among these nodes
If they're to move along some arc, please draw the arc. If the arc is an arc of a circle then the circle will have a center and a radius. Would that circle be the same as the red circle? Not sure what you mean by radius. Each of the points has it's own distance (radius) from the origin, and the red circle also has a radius. And an "arc" could also have a radius.
The star points are not on any arc. Do you need to put them on an arc first before rotating? Or do you want the whole cluster of starred points to move along some angle with respect to the origin and keep their respective radii, just basically swivel the whole group of them about some angle, so their relative positions in the group stays the same?
RED points are Users
BLACK AND BLUE stars are Drones
FIRST, the radius of arc is not same as the RED circle's radius.
SECOND, as I illustrated in the attach figure, these stars are drones and I scatterd them randomly and at the initial time t0 the drones will select random direction and move on straight lines after t time ( let say 1 second ) they will arrive to another position and try to change the direction without stoping (keep flying on arc as illustrated in the figure) NOT via choosing another random direction.
I assume each star (drone) do the above procedure seprately.
I hope the illustration in the figure let you get what I wanted to do.
thanks again for your reply
You just have to subtract the drone position so that the drone if at the origin. Then get the incoming/prior angle. And add the desired "turn" to that angle to get a new angle. Multiply by the radius to get the new location. Then add back in the original drone position to shift the system back to its original location.
I really appreciate your help
Please, would you give me an example, by coding, if you don't mind?

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Release

R2018a

Asked:

on 24 Nov 2021

Commented:

on 4 Dec 2021

Community Treasure Hunt

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

Start Hunting!