Home > matGeom > geom3d > isParallel3d.m

isParallel3d

PURPOSE ^

ISPARALLEL3D Check parallelism of two 3D vectors.

SYNOPSIS ^

function b = isParallel3d(v1, v2, varargin)

DESCRIPTION ^

ISPARALLEL3D Check parallelism of two 3D vectors.

   B = isParallel3d(V1, V2)
   where V1 and V2 are 2 [1x3] arrays, returns 1 if the vectors are
   parallels, and 0 otherwise.

   Also works when V1 and V2 are two [Nx3] arrays with same number of
   rows. In this case, return a [Nx1] array containing 1 at the positions
   of parallel vectors.

   Also works when one of V1 or V2 is scalar and the other one is [Nx3]
   array, in this case return [Nx1] results.

   B = isPerpendicular3d(V1, V2, TOL)
   Specifies the absolute tolerance (default is 1e-14).

   Example
   isParallel3d([1 2 1], [2 4 2])
   ans =
       1

   isParallel3d([1 2 1], [1 3 2])
   ans =
       0

   See also
   vectors3d, isPerpendicular3d

 ------
 Author: David Legland
 e-mail: david.legland@grignon.inra.fr
 Created: 2006-04-25
 Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function b = isParallel3d(v1, v2, varargin)
0002 %ISPARALLEL3D Check parallelism of two 3D vectors.
0003 %
0004 %   B = isParallel3d(V1, V2)
0005 %   where V1 and V2 are 2 [1x3] arrays, returns 1 if the vectors are
0006 %   parallels, and 0 otherwise.
0007 %
0008 %   Also works when V1 and V2 are two [Nx3] arrays with same number of
0009 %   rows. In this case, return a [Nx1] array containing 1 at the positions
0010 %   of parallel vectors.
0011 %
0012 %   Also works when one of V1 or V2 is scalar and the other one is [Nx3]
0013 %   array, in this case return [Nx1] results.
0014 %
0015 %   B = isPerpendicular3d(V1, V2, TOL)
0016 %   Specifies the absolute tolerance (default is 1e-14).
0017 %
0018 %   Example
0019 %   isParallel3d([1 2 1], [2 4 2])
0020 %   ans =
0021 %       1
0022 %
0023 %   isParallel3d([1 2 1], [1 3 2])
0024 %   ans =
0025 %       0
0026 %
0027 %   See also
0028 %   vectors3d, isPerpendicular3d
0029 %
0030 % ------
0031 % Author: David Legland
0032 % e-mail: david.legland@grignon.inra.fr
0033 % Created: 2006-04-25
0034 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas).
0035 
0036 % 2011.03.20 fix bug for set of 3 vectors
0037 
0038 % check if tolerance is specified
0039 tol = 1e-14;
0040 if ~isempty(varargin)
0041     tol = varargin{1};
0042 end
0043 
0044 % compute
0045 b = vectorNorm3d(crossProduct3d(v1, v2)) < tol;

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