Last active
August 29, 2015 14:17
-
-
Save knedlsepp/3e37f147cb4c94ae6223 to your computer and use it in GitHub Desktop.
Computing the distance of points and an affine space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function d = distancePointsAffineSpace(Points, Space) | |
lengths = @(X) sqrt(sum(X.^2,2)); | |
d = lengths(Points - projectPointsOntoAffineSpace(Points, Space)); | |
end | |
function [projectedPoints, coordinates] = projectPointsOntoAffineSpace(Points, Space) | |
%coordinates are with respect to an orthonormal base located in Space(1,:) | |
dirVecs = bsxfun(@minus, Space(2:end,:), Space(1,:)); | |
% Orthonormalize the direction vectors; | |
dirVecs = orth(dirVecs.').'; | |
% Compute coordinates with respect to (Space(1,:),dirVecs)-coordinates | |
coordinates = bsxfun(@minus, Points, Space(1,:))*dirVecs.'; | |
% Compute projection | |
projectedPoints = bsxfun(@plus, coordinates*dirVecs, Space(1,:)); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment