Skip to content

Instantly share code, notes, and snippets.

@awade
Created May 26, 2021 06:56
Show Gist options
  • Save awade/f9cc4aa7af23b4943dfc2151b33106a4 to your computer and use it in GitHub Desktop.
Save awade/f9cc4aa7af23b4943dfc2151b33106a4 to your computer and use it in GitHub Desktop.
Some Matlab code for generating random normal vectors uniformly distributed in angle
%% First a method using quaternions
qtn = randrot(1000,1);
pts = rotatepoint(qtn, [1 0 0]);
figure()
scatter3(pts(:,1), pts(:,2), pts(:,3))
axis equal
%% Second method (works only in the half sphere)
pts = zeros(3,500);
for ii = 1:length(pts)
[Q,~] = qr(randn(3));
pts(:,ii) = Q*[1 0 0]';
end
figure()
scatter3(pts(1,:), pts(2,:), pts(3,:))
axis equal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment