advance a vector coordinates in a loop

1 visualizzazione (ultimi 30 giorni)
Lama Hamadeh
Lama Hamadeh il 20 Mar 2021
Commentato: KSSV il 20 Mar 2021
Hi all,
I'd like to advance an intial vector forward in something similar to this:
where the blue arrow is the initial one, and the the green is the next one, and so on so forth. The code I have at the moment is:
%angle of the norm
theta_norm = pi/2;
%length of the vector (radius)
r = 0.7071/2;
%Initialise the arrow on the xy grid
x0 = 0.5; %initial x position
y0 = 0; %initial y position
%looping
for i = 1:4
%the angle between the vector and the norm (orientation)
theta = i*theta_norm - theta_xaxis;
%find out the Cartesian coordinates
x = r*cos(theta);
y = r*sin(theta);
%draw an arrow in each loop
quiver(x0,y0,x,y,0,'b','LineWidth',3) %here is my problem!!
pause(0.1)
end
Any help would be appreictaed! Thanks.

Risposte (1)

KSSV
KSSV il 20 Mar 2021
m = 25 ; n = 25 ;
x = linspace(0,1,m) ;
y = linspace(0,1,n) ;
dx = min(diff(x)) ;
dy = min(diff(y)) ;
dxy = sqrt(dx^2+dy^2) ;
[X,Y] = meshgrid(x,y) ;
%length of the vector (radius)
r = 0.7071/2;
theta = pi/4 ;
%Initialise the arrow on the xy grid
x0 = 0.5; %initial x position
y0 = 0; %initial y position
%looping
for i = 1:4
%the angle between the vector and the norm (orientation)
r = r+dxy ;
%find out the Cartesian coordinates
x = r*cos(theta);a = pi/4 ;
y = r*sin(theta);
%draw an arrow in each loop
plot(X,Y,'.r')
hold on
quiver(x0,y0,x,y,'b','LineWidth',3) %here is my problem!!
hold off
drawnow
pause(0.1)
end
  2 Commenti
Lama Hamadeh
Lama Hamadeh il 20 Mar 2021
Thanks for your reply and attempt to help! But when running your code, the blue arrow is still in the (x0=0.5,y0=0) poistion, i.e., it hasn't moved/translated to the second poition (x0=1,y0=0.5), and next to the third (x0=0.5,y0=1), and so on to the fourth position (x0=0,y0=0.5), which was my main problem.
Thanks.
KSSV
KSSV il 20 Mar 2021
Include another loop for x0 and y0.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by