Skip to content

Instantly share code, notes, and snippets.

@peteristhegreat
Created August 25, 2015 21:20
Show Gist options
  • Save peteristhegreat/0930260d107250301811 to your computer and use it in GitHub Desktop.
Save peteristhegreat/0930260d107250301811 to your computer and use it in GitHub Desktop.
Projects a point cloud in 3d space onto a plane defined by a normal unit vector and a point.
function P_project = projectPointsOntoPlane(uv, pointOnPlane, points)
% related: http://www.mathworks.com/matlabcentral/newsreader/view_thread/293244
% uv is a unit vector of the normal to the plane
% pointOnPlane is a point of the plane
% points is a point cloud that is to be projected (flattened) onto
% the plane
if(size(uv,1) == 3)
% one xyz point per column
Q = pointOnPlane';
m = size(points,2);
N2 = (uv').'*(uv');
P_project = points'*(eye(3)-N2) + repmat(Q*N2,m,1);
P_project = P_project';
else
% one xyz point per row
Q = pointOnPlane;
m = size(points,1);
N2 = uv.'*uv;
P_project = points*(eye(3)-N2) + repmat(Q*N2,m,1);
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment