2009-12-26 79 views

Trả lời

23
a = [2 3 5]; 
b = [1 1 0]; 
c = a+b; 

starts = zeros(3,3); 
ends = [a;b;c]; 

quiver3(starts(:,1), starts(:,2), starts(:,3), ends(:,1), ends(:,2), ends(:,3)) 
axis equal 
+0

rung động và quiver3 loại bỏ các khoảng trống giữa vectơ mà làm cho các vectơ trông giống như với cường độ nhỏ. – Aamir

+4

Hãy thử thêm tham số "tỷ lệ", đặt thành 0, để ngăn tự động chia tỷ lệ, nghĩa là 'quiver3 (bắt đầu (:, 1), bắt đầu (:, 2), bắt đầu (:, 3), kết thúc (:, 1), kết thúc (:, 2), kết thúc (:, 3), 0) ' –

+0

Cảm ơn Martin về đối số tỷ lệ. Nhưng các mũi tên trong quiver3 trông không đẹp lắm so với mũi tên.m từ Matlab File Exchage. – Aamir

2

Tôi không chắc chắn về cách thực hiện điều này trong 3D, nhưng trong 2D bạn có thể sử dụng lệnh compass.

16

Tôi đồng ý với Aamir rằng việc gửi arrow.m từ Erik Johnson trên MathWorks File Exchange là một lựa chọn rất tốt đẹp. Bạn có thể sử dụng nó để minh họa cho different methods of vector addition như vậy:

  • Mẹo-to-đuôi phương pháp: Phương pháp

    o = [0 0 0]; %# Origin 
    a = [2 3 5]; %# Vector 1 
    b = [1 1 0]; %# Vector 2 
    c = a+b;  %# Resultant 
    arrowStarts = [o; a; o];  %# Starting points for arrows 
    arrowEnds = [a; c; c];   %# Ending points for arrows 
    arrow(arrowStarts,arrowEnds); %# Plot arrows 
    
  • bình hành:

    o = [0 0 0]; %# Origin 
    a = [2 3 5]; %# Vector 1 
    b = [1 1 0]; %# Vector 2 
    c = a+b;  %# Resultant 
    arrowStarts = [o; o; o];  %# Starting points for arrows 
    arrowEnds = [a; b; c];   %# Ending points for arrows 
    arrow(arrowStarts,arrowEnds); %# Plot arrows 
    hold on; 
    lineX = [a(1) b(1); c(1) c(1)]; %# X data for lines 
    lineY = [a(2) b(2); c(2) c(2)]; %# Y data for lines 
    lineZ = [a(3) b(3); c(3) c(3)]; %# Z data for lines 
    line(lineX,lineY,lineZ,'Color','k','LineStyle',':'); %# Plot lines 
    
3

tôi đã làm nó này cách,

2D

% vectors I want to plot as rows (XSTART, YSTART) (XDIR, YDIR) 
rays = [ 
    1 2 1 0 ; 
    3 3 0 1 ; 
    0 1 2 0 ; 
    2 0 0 2 ; 
] ; 

% quiver plot 
quiver(rays(:,1), rays(:,2), rays(:,3), rays(:,4)); 

3D

% vectors I want to plot as rows (XSTART, YSTART, ZSTART) (XDIR, YDIR, ZDIR) 
rays = [ 
    1 2 0 1 0 0; 
    3 3 2 0 1 -1 ; 
    0 1 -1 2 0 8; 
    2 0 0 0 2 1; 
] ; 

% quiver plot 
quiver3(rays(:,1), rays(:,2), rays(:,3), rays(:,4), rays(:,5), rays(:,6)); 

Dựa trên các tài liệu quiverquiver3

-1
  % draw simple vector from pt a to pt b 
      % wtr : with respect to 
      scale=0;%for drawin vectors with true scale 
      a = [10 20 30];% wrt origine O(0,0,0) 
      b = [10 10 20];% wrt origine O(0,0,0) 

      starts=a;% a now is the origine of my vector to draw (from a to b) so we made a translation from point O to point a = to vector a 
      c = b-a;% c is the new coordinates of b wrt origine a 
      ends=c;% 
      plot3(a(1),a(2),a(3),'*b') 
      hold on 
      plot3(b(1),b(2),b(3),'*g') 

      quiver3(starts(:,1), starts(:,2), starts(:,3), ends(:,1), ends(:,2), ends(:,3),scale);% Use scale = 0 to plot the vectors without the automatic scaling. 
      % axis equal 
      hold off 
Các vấn đề liên quan