advance a vector coordinates in a loop
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
KSSV
am 20 Mär. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!