Created
May 26, 2021 06:56
-
-
Save awade/f9cc4aa7af23b4943dfc2151b33106a4 to your computer and use it in GitHub Desktop.
Some Matlab code for generating random normal vectors uniformly distributed in angle
This file contains hidden or 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
%% 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