Je voudrais tracer la façon dont l'amplitude et l'orientation d'un vecteur 2D évoluent dans le temps. Pour ce faire, je voudrais créer un graphique qui rappelle les graphiques canoniques E & B que vous pouvez vous rappeler d'une classe introductive d'électricité et de magnétisme. En particulier, je voudrais connecter mes points vectoriels 2D avec un ruban, afin qu'ils soient faciles à voir. Existe-t-il un moyen simple de le faire dans MATLAB? quiver3
est assez proche, mais il manque le ruban. Peut-être une sorte de surface paramétrique?Tracer l'évolution du vecteur 2D en 3D sous forme de ruban dans MATLAB
Répondre
est ici une solution qui tire un ruban entre une deux lignes dans l'espace 3D. vous pouvez tracer votre carquois par-dessus & ajuster l'opacité en utilisant 'FaceAlpha' comme dans la solution de gnovice
Pour rendre la fonction plus claire, je l'affiche d'abord sans fonctions de vérification d'erreur et de redimensionnement (qui constituent la majeure partie du corps de la fonction & ne sont pas particulièrement intéressantes)
function h = filledRibbon (x,y,z,u,v,w,c, varargin)
%function filledRibbon (x,y,z,u,v,w,c, varargin)
%
%plots a ribbon spanning the area between the lines x,y,z and x+u,y+v,z+w
%in the color c
%varargin is passed directly to patch
%returns a handle to the patch graphic created
%make up a set of regions that span the space between the lines
xr = [x(1:end-1); x(1:end-1) + u(1:end-1); x(2:end) + u(2:end); x(2:end)];
yr = [y(1:end-1); y(1:end-1) + v(1:end-1); y(2:end) + v(2:end); y(2:end)];
zr = [z(1:end-1); z(1:end-1) + w(1:end-1); z(2:end) + w(2:end); z(2:end)];
%plot the regions with no edges
h = patch(xr,yr,zr,c, 'LineStyle','none', varargin{:});
utiliser cette version de vérification des erreurs dans votre code actuel:
function h = filledRibbon (x,y,z,u,v,w,c, varargin)
%function filledRibbon (x,y,z,u,v,w,c, varargin)
%
%plots a ribbon spanning the area between the lines x,y,z and x+u,y+v,z+w
%in the color c
%varargin is passed directly to patch
%returns a handle to the patch graphic created
if ~exist('w', 'var') || isempty(w)
w = 0;
end
if ~exist('u', 'var') || isempty(u)
u = 0;
end
if ~exist('v', 'var') || isempty(v)
v = 0;
end
if ~exist('c', 'var') || isempty(c)
c = 'b';
end
%make all vectors 1xN
x = reshape(x,1,[]);
y = reshape(y,1,[]);
z = reshape(z,1,[]);
%if any offsets are scalar, expand to a vector
if all(size(u) == 1)
u = repmat(u, size(x));
end
if all(size(v) == 1)
v = repmat(v, size(x));
end
if all(size(w) == 1)
w = repmat(w, size(x));
end
%make up a set of regions that span the space between the lines
xr = [x(1:end-1); x(1:end-1) + u(1:end-1); x(2:end) + u(2:end); x(2:end)];
yr = [y(1:end-1); y(1:end-1) + v(1:end-1); y(2:end) + v(2:end); y(2:end)];
zr = [z(1:end-1); z(1:end-1) + w(1:end-1); z(2:end) + w(2:end); z(2:end)];
%plot the regions with no edges
h = patch(xr,yr,zr,c, 'LineStyle','none', varargin{:});
Vous pouvez utiliser les fonctions complotant FILL3 et QUIVER3 faire quelque chose comme ceci:
x = linspace(0,4*pi,30); %# Create some x data
y1 = sin(x); %# Create wave 1
y2 = sin(x-pi); %# Create wave 2
u = zeros(size(x)); %# Create a vector of zeroes
hRibbon1 = fill3(x,y1,u,'r'); %# Plot wave 1 and fill underneath with color
set(hRibbon1,'EdgeColor','r',... %# Change the edge color and
'FaceAlpha',0.5); %# make the colored patch transparent
hold on; %# Add to the existing plot
quiver3(x,u,u,u,y1,u,0,'r'); %# Plot the arrows
hRibbon2 = fill3(x,u,y2,'b'); %# Plot wave 2 and fill underneath with color
set(hRibbon2,'EdgeColor','b',... %# Change the edge color and
'FaceAlpha',0.5); %# make the colored patch transparent
quiver3(x,u,u,u,u,y2,0,'b'); %# Plot the arrows
axis equal; %# Use equal axis scaling
Et voici l'intrigue résultant:
Ceci est tout à fait brillant et exactement le chiffre récapitule, mais il a quelques limitations pour ce que j'essaie de faire. Je suis intéressé par le cas où le vecteur peut tourner. Par exemple. y = sin (t), x = sin (t-pi/2) et où le vecteur est libre de ne pas nécessairement commencer ou finir à zéro. En d'autres termes, un ruban torsadé. Dans cet exemple, le ruban ne fonctionne que si le vecteur commence ou finit à zéro et le remplissage ne semble pas bien traiter une courbe de torsion. Je m'excuse si cela était moins clair dans la question. J'ai eu du mal à trouver un diagramme de ruban sinueux en ligne. – AndyL
Brillant! J'ai couru ceci: x = [0: .1: 3 * pi]; w = sin (x); v = cos (x); u = zéros (taille (x)); y = zéros (taille (x)); z = zéros (taille (x)); c = 'r'; filledRibbon (x, y, z, u, v, w, c, «FaceAlpha», 0,2); axe vis3d; Il fonctionne comme un charme. – AndyL