advance a vector coordinates in a loop
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
KSSV
2021-3-20
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!