DRAWAXIS3D Draw a coordinate system and an origin. drawAxis3d Adds three 3D arrows to the current axis, corresponding to the directions of the 3 basis vectors Ox, Oy and Oz. Ox vector is red, Oy vector is green, and Oz vector is blue. drawAxis3d(L, R) Specifies the length L and the radius of the cylinders representing the different axes. drawAxis3d(..., 'TFM', TRANSFORM) Transforms the coordinate system before drawing using TRANSFORM. H = drawAxis3d(...) returns the group handle of the axis object. Example drawAxis3d figure; drawAxis3d(20, 1); view([135,15]); lighting('phong'); camlight('head'); axis('equal') xlabel X; ylabel Y; zlabel Z See also drawAxisCube
0001 function varargout = drawAxis3d(varargin) 0002 %DRAWAXIS3D Draw a coordinate system and an origin. 0003 % 0004 % drawAxis3d 0005 % Adds three 3D arrows to the current axis, corresponding to the 0006 % directions of the 3 basis vectors Ox, Oy and Oz. 0007 % Ox vector is red, Oy vector is green, and Oz vector is blue. 0008 % 0009 % drawAxis3d(L, R) 0010 % Specifies the length L and the radius of the cylinders representing the 0011 % different axes. 0012 % 0013 % drawAxis3d(..., 'TFM', TRANSFORM) 0014 % Transforms the coordinate system before drawing using TRANSFORM. 0015 % 0016 % H = drawAxis3d(...) returns the group handle of the axis object. 0017 % 0018 % Example 0019 % drawAxis3d 0020 % 0021 % figure; 0022 % drawAxis3d(20, 1); 0023 % view([135,15]); lighting('phong'); camlight('head'); axis('equal') 0024 % xlabel X; ylabel Y; zlabel Z 0025 % 0026 % See also 0027 % drawAxisCube 0028 % 0029 0030 % ------ 0031 % Author: David Legland 0032 % E-mail: david.legland@inrae.fr 0033 % Created: 2007-08-14, using Matlab 7.4.0.287 (R2007a) 0034 % Copyright 2007-2024 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas 0035 0036 % extract handle of axis to draw on 0037 if isempty(varargin) 0038 hAx = gca; 0039 else 0040 if isAxisHandle(varargin{1}) 0041 hAx = varargin{1}; 0042 varargin(1) = []; 0043 else 0044 hAx = gca; 0045 end 0046 end 0047 0048 0049 % Parsing 0050 p = inputParser; 0051 addOptional(p, 'L', 1, @(x)validateattributes(x, {'numeric'},... 0052 {'scalar','nonempty','real','finite','positive','nonnan'})); 0053 addOptional(p, 'R', [], @(x)validateattributes(x, {'numeric'},... 0054 {'scalar','nonempty','real','finite','positive','nonnan'})); 0055 addParameter(p, 'TFM', eye(4), @isTransform3d); 0056 parse(p,varargin{:}); 0057 0058 L = p.Results.L; 0059 R = p.Results.R; 0060 if isempty(R) 0061 R = L/10; 0062 elseif R/L > 0.1 0063 R = (0.1-eps)*L; 0064 warning('Value of R is invalid and was ignored!') 0065 end 0066 TFM = p.Results.TFM; 0067 0068 % geometrical data 0069 origin = transformPoint3d(zeros(3,3), TFM); 0070 vector = transformVector3d(eye(3,3), TFM); 0071 color = eye(3,3); 0072 0073 % draw three arrows and a ball 0074 hold on; 0075 sh = drawArrow3d(hAx, origin, vector*L, color, 'arrowRadius', R/L); 0076 sh(4) = drawSphere(hAx, [origin(1,:) 2*R], 'faceColor', 'black'); 0077 gh = hggroup(hAx); 0078 set(sh, 'Parent', gh) 0079 0080 if nargout > 0 0081 varargout = {gh}; 0082 end