Project3dVectors.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. % Project3dVectors.m
  2. %
  3. % This function takes as input a list of Cartesian vectors and moves them to the
  4. % place of the equirectangular video with the least distortion. This is
  5. % achieved by finding the rotation of the mean vector to the center of the
  6. % video. Then it transforms all the vectors based on this rotation (i.e around
  7. % the center of the equirectangular video). In this way most traditional
  8. % algorithms can work directly on the transformed data.
  9. %
  10. % Note: in order for this method to work properly the vertical dispersion of the
  11. % provided vectors has to be relatively small (< 45 degrees) in order to be in
  12. % the almost linear part of the equirectangular video.
  13. %
  14. % input:
  15. % vectorList - list of vectors in spherical coordinates
  16. % metadata - metadata of the ARFF file
  17. %
  18. % output:
  19. % coords - 2D x,y coordinates of the projected vectors
  20. function [coords] = Project3dVectors(vecList, metadata)
  21. meanVec = mean(vecList,1)';
  22. videoMidVec = [-1; 0; 0];
  23. rot = HeadToVideoRot(meanVec, 0, videoMidVec);
  24. rot = rot'; % get rotation to middle of video
  25. coords = zeros(size(vecList,1), 2);
  26. maxVerRads = 0;
  27. minVerRads = pi;
  28. for ind=1:size(vecList,1)
  29. curVec = vecList(ind,:);
  30. rotVec = RotatePoint(rot, curVec);
  31. [horRads, verRads] = CartToSpherical(rotVec);
  32. maxVerRads = max(maxVerRads, verRads);
  33. minVerRads = min(minVerRads, verRads);
  34. [coords(ind,1), coords(ind,2)] = SphericalToEquirect(horRads, verRads, metadata.width_px, metadata.height_px);
  35. end
  36. end