Home > matGeom > geom3d > drawAxis3d.m

drawAxis3d

PURPOSE ^

DRAWAXIS3D Draw a coordinate system and an origin.

SYNOPSIS ^

function varargout = drawAxis3d(varargin)

DESCRIPTION ^

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

 ------
 Author: David Legland
 e-mail: david.legland@nantes.inra.fr
 Created: 2007-08-14,    using Matlab 7.4.0.287 (R2007a)
 Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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 % Author: David Legland
0031 % e-mail: david.legland@nantes.inra.fr
0032 % Created: 2007-08-14,    using Matlab 7.4.0.287 (R2007a)
0033 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas.
0034 
0035 % Check if axes handle is specified
0036 hAx = gca;
0037 if ~isempty(varargin)
0038     if isAxisHandle(varargin{1})
0039         hAx = varargin{1};
0040         varargin(1)=[];
0041     end
0042 end
0043 
0044 % Parsing
0045 p = inputParser;
0046 addOptional(p,'L',1, @(x)validateattributes(x,{'numeric'},...
0047     {'scalar','nonempty','real','finite','positive','nonnan'}));
0048 addOptional(p,'R',[], @(x)validateattributes(x,{'numeric'},...
0049     {'scalar','nonempty','real','finite','positive','nonnan'}));
0050 addParameter(p,'TFM',eye(4), @isTransform3d);
0051 parse(p,varargin{:});
0052 
0053 L = p.Results.L;
0054 R = p.Results.R;
0055 if isempty(R)
0056     R=L/10;
0057 elseif R/L > 0.1
0058     R = (0.1-eps)*L;
0059     warning('Value of R is invalid and was ignored!')
0060 end
0061 TFM = p.Results.TFM;
0062 
0063 % geometrical data
0064 origin = transformPoint3d(zeros(3,3), TFM);
0065 vector = transformVector3d(eye(3,3), TFM);
0066 color = eye(3,3);
0067 
0068 % draw three arrows and a ball
0069 hold on;
0070 sh=drawArrow3d(hAx, origin, vector*L, color, 'arrowRadius', R/L);
0071 sh(4)=drawSphere(hAx,[origin(1,:) 2*R], 'faceColor', 'black');
0072 gh = hggroup(hAx);
0073 set(sh,'Parent',gh)
0074 
0075 if nargout > 0
0076     varargout = {gh};
0077 end

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019