diff --git a/SFS_ir/get_ir.m b/SFS_ir/get_ir.m index 75f7a838..b377d8f5 100644 --- a/SFS_ir/get_ir.m +++ b/SFS_ir/get_ir.m @@ -166,17 +166,21 @@ end % Find nearest head orientation in the horizontal plane [phi,theta] = sofa_get_head_orientations(header); - [neighbours_head,idx_head] = ... - findnearestneighbour([phi theta]',head_orientation,3); + [x(:,1),x(:,2),x(:,3)] = sph2cart(phi,theta,ones(length(phi),1)); + [x_desired(1),x_desired(2),x_desired(3)] = ... + sph2cart(head_orientation(1),head_orientation(2),1); + [neighbours,idx_head] = findnearestneighbour(x',x_desired',3); + [neighbours_head(1,:),neighbours_head(2,:)] = ... + cart2sph(neighbours(1,:),neighbours(2,:),neighbours(3,:)); % Check if head orientation is out of bounds - if all(abs(head_orientation(1))>abs(neighbours_head(1,:))) + if all(abs(head_orientation(1))-abs(neighbours_head(1,:))>0.001) warning('SFS:get_ir',['Head azimuth %.1f deg out of bound, ', ... 'using %.1f deg instead.'], ... deg(head_orientation(1)), ... deg(neighbours_head(1,1))); head_orientation(1) = neighbours_head(1,1); end - if all(abs(head_orientation(2))>abs(neighbours_head(2,:))) + if all(abs(head_orientation(2))-abs(neighbours_head(2,:))>0.001) warning('SFS:get_ir',['Head elevation %.1f deg out of bound, ', ... 'using %.1f deg instead.'], ... deg(head_orientation(2)), ...