normalizeVector3d.m 687 B

123456789101112131415161718192021222324252627
  1. function vn = normalizeVector3d(v)
  2. %NORMALIZEVECTOR3D Normalize a 3D vector to have norm equal to 1.
  3. %
  4. % V2 = normalizeVector3d(V);
  5. % Returns the normalization of vector V, such that ||V|| = 1. Vector V is
  6. % given as a row vector.
  7. %
  8. % If V is a N-by-3 array, normalization is performed for each row of the
  9. % input array.
  10. %
  11. % See also:
  12. % vectors3d, vectorNorm3d
  13. %
  14. % ---------
  15. % author : David Legland
  16. % INRA - TPV URPOI - BIA IMASTE
  17. % created the 29/11/2004.
  18. %
  19. % HISTORY
  20. % 2005-11-30 correct a bug
  21. % 2009-06-19 rename as normalizeVector3d
  22. % 2010-11-16 use bsxfun (Thanks to Sven Holcombe)
  23. vn = bsxfun(@rdivide, v, sqrt(sum(v.^2, 2)));