How to plot circle with direction?

조회 수: 35 (최근 30일)
Megha
Megha 2019년 9월 10일
댓글: michael 2021년 1월 20일
I wish to plot a circle with direction of its motion.An exmaple is attached below.Path_Ideal.jpg
I wish to get around 5-10 arrows per circle (that can be chnaged as per our need).
Below attached matlab.mat file is the data file.
The code goes like:
subplot(2,2,[1 3])
h1 = plot(x, y, '-','Color','b','LineWidth',2);
Now I dont know how to put 5-10 arrows showing direction.
Can anyone help?

답변 (1개)

Bruno Luong
Bruno Luong 2019년 9월 10일
편집: Bruno Luong 2019년 9월 10일
2D version. adapt to your need
% circle parameter
r = 5;
cx = 0;
cy = 0;
cfun = @(tt) [cx+r*cos(tt); cy+r*sin(tt)];
xy = cfun(linspace(0,2*pi,361));
close all
hold on
plot(xy(1,:),xy(2,:),'b');
% arrows parameters
m = 10; % number of arrows
h = 0.1*r; % height
w = 0.1*r; % width
dir = -1; % 1 anticlock, -1 clock
a = [-w/2 0 w/2;
-dir*h 0 -dir*h];
for k=1:m
tt = 2*pi*k/m;
R = [cos(tt) -sin(tt);
sin(tt) cos(tt)];
xy = cfun(tt)+ R*a;
plot(xy(1,:),xy(2,:),'b');
end
axis equal
  댓글 수: 5
Megha
Megha 2019년 9월 11일
I have tried the following code, but arrows are too close to each other, in this case, to see the dirction of motion of circle.
rMag = 0.5;
lenTime = length(x);
% Indices of tails of arrows
vSelect0 = 1:(lenTime-1);
% Indices of tails of arrows
vSelect1 = vSelect0 + 1;
% X coordinates of tails of arrows
vXQ0 = x(vSelect0, 1); % x last removed
% Y coordinates of tails of arrows
vYQ0 = y(vSelect0, 1); % y last removed
% X coordinates of heads of arrows
vXQ1 = x(vSelect1, 1); % x first removed
% Y coordinates of heads of arrows
vYQ1 = y(vSelect1, 1); % y first remove
% vector difference between heads & tails
vPx = (vXQ1 - vXQ0) * rMag;
vPy = (vYQ1 - vYQ0) * rMag;
% add arrows
h2 = quiver (vXQ0,vYQ0, vPx, vPy, 0, 'b'); grid on; hold off
axis equal
michael
michael 2021년 1월 20일
I'w suggest to set
X = 10; % this is step size - each 10th point will have a vector
vSelect0 = 1:X:(lenTime-1);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Thermal Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by