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
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@inrae.fr 0033 % Created: 2006-04-25 0034 % Copyright 2006-2024 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas) 0035 0036 % check if tolerance is specified 0037 tol = 1e-14; 0038 if ~isempty(varargin) 0039 tol = varargin{1}; 0040 end 0041 0042 % compute 0043 b = vectorNorm3d(crossProduct3d(v1, v2)) < tol;