advance a vector coordinates in a loop
1 回表示 (過去 30 日間)
古いコメントを表示
Hi all,
I'd like to advance an intial vector forward in something similar to this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/556632/image.png)
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
2 件のコメント
参考
カテゴリ
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!