Home > matGeom > geom3d > drawAngleBetweenVectors3d.m

drawAngleBetweenVectors3d

PURPOSE ^

DRAWANGLEBETWEENVECTORS3D Draw an arc between 2 vectors.

SYNOPSIS ^

function varargout = drawAngleBetweenVectors3d(o, v1, v2, r, 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(o, v1, v2, r, 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 % Created: 2020-02-02
0030 % Copyright 2020
0031 
0032 % parse axis handle
0033 hAx = gca;
0034 if isAxisHandle(o)
0035     hAx = o;
0036     o = v1;
0037     v1 = v2;
0038     v2 = r;
0039     r = varargin{1};
0040     varargin(1) = [];
0041 end
0042 
0043 p = inputParser;
0044 p.KeepUnmatched = true;
0045 logParValidFunc=@(x) (islogical(x) || isequal(x,1) || isequal(x,0));
0046 addParameter(p,'ConjugateAngle',false,logParValidFunc);
0047 parse(p, varargin{:});
0048 conjugate=p.Results.ConjugateAngle;
0049 drawOptions=p.Unmatched;
0050 
0051 % Normal of the two vectors
0052 normal=normalizeVector3d(crossProduct3d(v1, v2));
0053 % Align normal with the z axis.
0054 ROT = createRotationVector3d(normal,[0 0 1]);
0055 % Align first vector with x axis
0056 ROTv1 = createRotationVector3d(transformVector3d(v1,ROT),[1 0 0]);
0057 % Get Euler angles of the arc.
0058 % The arc is an flat object. Hence, use the 'ZYZ' convention.
0059 [PHI, THETA, PSI] = rotation3dToEulerAngles((ROTv1*ROT)','ZYZ');
0060 % Get angle between the vectors
0061 angle=rad2deg(vectorAngle3d(v1, v2));
0062 % Draw the arc
0063 if ~conjugate
0064     h = drawCircleArc3d(hAx, [o r [THETA PHI PSI] 0 angle],drawOptions);
0065 else
0066     h = drawCircleArc3d(hAx, [o r [THETA PHI PSI] 0 angle-360],drawOptions);
0067 end
0068 
0069 % Format output
0070 if nargout > 0
0071     varargout{1} = h;
0072 end

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