How to plot circle with direction?
이전 댓글 표시
I wish to plot a circle with direction of its motion.An exmaple is attached below.

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
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
Bruno Luong
2019년 9월 10일
편집: Bruno Luong
2019년 9월 10일
3D version:

% circle parameters
r = 5;
cxyz = [0; 0; 0]; % center
N = randn(3,1); % normal to circle plane
N = N(:)/norm(N);
Q = null(N');
cfun = @(tt) cxyz + r*Q*[cos(tt); sin(tt)];
close all
hold on
xyz = cfun(linspace(0,2*pi,361));
plot3(xyz(1,:),xyz(2,:),xyz(3,:),'b');
% 3D arrows parameters
m = 10; % number of arrows
h = 0.12*r; % height
w = 0.08*r; % width
dir = -1; % 1 anticlock, -1 clock
p = 16; % #circular discretization of the arrow
phi = linspace(0,2*pi,p+1);
Va = [(w/2)*cos(phi);
(-dir*h)+zeros(size(phi));
(w/2)*sin(phi)];
Va(:,end+1) = [0; 0; 0];
F = [ 1:p;
2:p+1;
(p+2)+zeros(1,p)].';
F2 = 1:p+1;
Q = [Q, N];
for k=1:m
tt = 2*pi*k/m;
R = [cos(tt) -sin(tt) 0;
sin(tt) cos(tt) 0;
0 0 1];
Vk = cfun(tt)+ Q*R*Va;
patch('Faces', F, 'Vertices', Vk', 'FaceColor', 'b', 'EdgeColor', 'none');
patch('Faces', F2, 'Vertices', Vk', 'FaceColor', 'b', 'EdgeColor', 'none');
end
axis equal
view(3);
Bruno Luong
2019년 9월 11일
편집: Bruno Luong
2019년 9월 11일
No sorry, I won't process your data.
I let you adapt the code and plot exactly the way you like. If you have specific question feel free to ask.
Megha
2019년 9월 11일
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);
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
