%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% VECT_ARROW(P0, P1, COLOR) VECT_ARROW(P0, P1) plots a line vector with arrow pointing from point P0 to point P1. Example: %3D vector p0 = [1 2 3]; % First point p0 p1 = [4 5 6]; % Second point p1 vectarrow(p0, p1) See also DRAW_LINK, DRAW_PATCH, DRAWROBOT3D. Author: Arturo Gil. Universidad Miguel Hernández de Elche. email: arturo.gil@umh.es date: 25/02/2012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0002 % VECT_ARROW(P0, P1, COLOR) 0003 % 0004 % VECT_ARROW(P0, P1) plots a line vector with arrow pointing from point P0 0005 % to point P1. 0006 % 0007 % Example: 0008 % %3D vector 0009 % p0 = [1 2 3]; % First point p0 0010 % p1 = [4 5 6]; % Second point p1 0011 % vectarrow(p0, p1) 0012 % 0013 % See also DRAW_LINK, DRAW_PATCH, DRAWROBOT3D. 0014 % 0015 % Author: Arturo Gil. Universidad Miguel Hernández de Elche. 0016 % email: arturo.gil@umh.es date: 25/02/2012 0017 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0018 0019 % Copyright (C) 2012, by Arturo Gil Aparicio 0020 % 0021 % This file is part of ARTE (A Robotics Toolbox for Education). 0022 % 0023 % ARTE is free software: you can redistribute it and/or modify 0024 % it under the terms of the GNU Lesser General Public License as published by 0025 % the Free Software Foundation, either version 3 of the License, or 0026 % (at your option) any later version. 0027 % 0028 % ARTE is distributed in the hope that it will be useful, 0029 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0030 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0031 % GNU Lesser General Public License for more details. 0032 % 0033 % You should have received a copy of the GNU Leser General Public License 0034 % along with ARTE. If not, see <http://www.gnu.org/licenses/>. 0035 function vect_arrow(p0, p1, color, width) 0036 0037 if ~exist('width', 'var') 0038 w = 3; 0039 else 0040 w=width; 0041 end 0042 0043 x0 = p0(1); 0044 y0 = p0(2); 0045 z0 = p0(3); 0046 x1 = p1(1); 0047 y1 = p1(2); 0048 z1 = p1(3); 0049 plot3([x0;x1],[y0;y1],[z0;z1], color, 'LineWidth',w); % Draw a line between p0 and p1 0050 0051 p = p1-p0; 0052 alpha = 0.1; 0053 beta = 0.1; 0054 0055 hu = [x1-alpha*(p(1)+beta*(p(2)+eps)); x1; x1-alpha*(p(1)-beta*(p(2)+eps))]; 0056 hv = [y1-alpha*(p(2)-beta*(p(1)+eps)); y1; y1-alpha*(p(2)+beta*(p(1)+eps))]; 0057 hw = [z1-alpha*p(3);z1;z1-alpha*p(3)]; 0058 0059 plot3(hu(:),hv(:),hw(:), color) % Plot arrow head 0060