Home > matGeom > geom3d > drawAngleBetweenVectors3d.m

drawAngleBetweenVectors3d

PURPOSE ^

DRAWANGLEBETWEENVECTORS3D Draw an arc between 2 vectors.

SYNOPSIS ^

function varargout = drawAngleBetweenVectors3d(varargin)

DESCRIPTION ^

DRAWANGLEBETWEENVECTORS3D Draw an arc between 2 vectors.

   drawAngleBetweenVectors3d(ORIGIN, VECTOR1, VECTOR2, RADIUS) 
   draws the arc between VECTOR1 and VECTOR2.

   drawAngleBetweenVectors3d(...,'ConjugateAngle',1) draws the conjugate
   angle instead of the small angle. Default is false.
   
   H = drawAngleBetweenVectors3d(...)
   returns the handle of the created LINE object
   
   Example
     o=-100 + 200*rand(1,3);
     v1=normalizeVector3d(-1 + 2*rand(1,3));
     v2=normalizeVector3d(-1 + 2*rand(1,3));
     r = rand;
     figure('color','w'); view(3)
     hold on; axis equal tight; xlabel X; ylabel Y; zlabel Z;
     drawVector3d(o, v1, 'r')
     drawVector3d(o, v2, 'g')
     drawAngleBetweenVectors3d(o, v1, v2, r,'Color','m','LineWidth', 3)

   See also
     drawCircleArc3d

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = drawAngleBetweenVectors3d(varargin)
0002 %DRAWANGLEBETWEENVECTORS3D Draw an arc between 2 vectors.
0003 %
0004 %   drawAngleBetweenVectors3d(ORIGIN, VECTOR1, VECTOR2, RADIUS)
0005 %   draws the arc between VECTOR1 and VECTOR2.
0006 %
0007 %   drawAngleBetweenVectors3d(...,'ConjugateAngle',1) draws the conjugate
0008 %   angle instead of the small angle. Default is false.
0009 %
0010 %   H = drawAngleBetweenVectors3d(...)
0011 %   returns the handle of the created LINE object
0012 %
0013 %   Example
0014 %     o=-100 + 200*rand(1,3);
0015 %     v1=normalizeVector3d(-1 + 2*rand(1,3));
0016 %     v2=normalizeVector3d(-1 + 2*rand(1,3));
0017 %     r = rand;
0018 %     figure('color','w'); view(3)
0019 %     hold on; axis equal tight; xlabel X; ylabel Y; zlabel Z;
0020 %     drawVector3d(o, v1, 'r')
0021 %     drawVector3d(o, v2, 'g')
0022 %     drawAngleBetweenVectors3d(o, v1, v2, r,'Color','m','LineWidth', 3)
0023 %
0024 %   See also
0025 %     drawCircleArc3d
0026 
0027 % ------
0028 % Author: oqilipo
0029 % E-mail: N/A
0030 % Created: 2020-02-02
0031 % Copyright 2020-2024
0032 
0033 % extract handle of axis to draw on
0034 [hAx, varargin] = parseAxisHandle(varargin{:});
0035 
0036 % retrieve inputs
0037 if length(varargin) < 4
0038     error('Requires at least four input arguments');
0039 end
0040 o = varargin{1};
0041 v1 = varargin{2};
0042 v2 = varargin{3};
0043 r = varargin{4};
0044 varargin(1:4) = [];
0045 
0046 % parse optional arguments
0047 p = inputParser;
0048 p.KeepUnmatched = true;
0049 logParValidFunc = @(x) (islogical(x) || isequal(x,1) || isequal(x,0));
0050 addParameter(p, 'ConjugateAngle', false, logParValidFunc);
0051 parse(p, varargin{:});
0052 conjugate = p.Results.ConjugateAngle;
0053 drawOptions = p.Unmatched;
0054 
0055 % Normal of the two vectors
0056 normal = normalizeVector3d(crossProduct3d(v1, v2));
0057 % Align normal with the z axis.
0058 ROT = createRotationVector3d(normal,[0 0 1]);
0059 % Align first vector with x axis
0060 ROTv1 = createRotationVector3d(transformVector3d(v1,ROT),[1 0 0]);
0061 % Get Euler angles of the arc.
0062 % The arc is an flat object. Hence, use the 'ZYZ' convention.
0063 [PHI, THETA, PSI] = rotation3dToEulerAngles((ROTv1*ROT)', 'ZYZ');
0064 % Get angle between the vectors
0065 angle = rad2deg(vectorAngle3d(v1, v2));
0066 % Draw the arc
0067 if ~conjugate
0068     h = drawCircleArc3d(hAx, [o r [THETA PHI PSI] 0 angle], drawOptions);
0069 else
0070     h = drawCircleArc3d(hAx, [o r [THETA PHI PSI] 0 angle-360], drawOptions);
0071 end
0072 
0073 % Format output
0074 if nargout > 0
0075     varargout{1} = h;
0076 end

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022