GetDispersion.m 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. % GetDispersion.m
  2. %
  3. % This function returns the minimum angle (half of the total) of a cone
  4. % starting from the beginning of the coordinate system, which is the place in
  5. % the middle of the 360 degree sphere, with the cone vector denoting the
  6. % direction of the middle of the cone that contains all the data points.
  7. %
  8. % input:
  9. % coneVec - vector denoting the direction of the cone
  10. % vecList - nx3 list of vectors
  11. %
  12. % output:
  13. % dispersion - cone angle (degrees) that contains all vectors
  14. % index - index to vector list that gave the maximum radius
  15. function [dispersion, index] = GetDispersion(coneVec, vecList)
  16. assert(size(vecList,2) == 3, 'Vector list not in correct format');
  17. if (size(coneVec,1) > size(coneVec,2))
  18. coneVec = coneVec';
  19. end
  20. assert(size(coneVec,1) == 1 && size(coneVec,2) == 3, 'Provided vector has wrong dimensions');
  21. c_maxDelta = 0.001;
  22. dispersion = 0;
  23. for ind=1:size(vecList,1)
  24. dotProd = sum(coneVec .* vecList(ind,:));
  25. assert(dotProd < 1+c_maxDelta, 'Provided vectors are not normalized');
  26. % account for double roundings
  27. if (dotProd > 1)
  28. dotProd = 1;
  29. end
  30. rads = acos(dotProd);
  31. if (rads >= dispersion)
  32. dispersion = rads;
  33. index = ind;
  34. end
  35. end
  36. dispersion = dispersion * 180 / pi;
  37. end