- /
- 
        Universe in a Nutshell
        on 16 Oct 2021
        
        
 
    - 11
- 147
- 7
- 0
- 280
% set background
figure(Color='k')
hold
% function shortcuts
m=@(a,c)max(min(a,c),-c);
s=@vecnorm;
n=@(p)p./s(p);
% random uniformly distributed values on the unit sphere
P=n(randn(3,1e3));
% iterate gravitational force exchange
A=copper(320);
for k=1:320
    Q=P;
    % distance of all points to each other
    D=reshape(P,3,1,[])-P;
    % calculate gravitational exchange force
    U=sum(m(D./s(D).^2,10),3)/1e4-1e-3;
    % add bounded, cumulative displacement and project result to unit sphere
    P=n(P+n(U).*m(s(U),.01));
    % plot imitating more points than actually calculated
    h=scatter(P(1,:),P(2,:),m(s(P-Q).^-3/1e8,80),A(k,:),'filled');
    alpha(h,.3)
end
axis off equal


 

 
             
             
             
               
               
               
               
               
               
