from
Sphere Collider
by Ligong Han
This is a simple physics engine for simulating sphere collision.
|
| combination(m,n,r)
|
function c = combination(m,n,r)
%COMBINATION Returns a nCr*r matrix C.
% nCr represents the total number of different mothods of selecting r
% numbers from m to n.
%
% Copyright Phymhan Studio.
% $Revision: 1.1 $ $Date: 2013/03/27 13:12:37 $
%
if nargin == 2
r = n;
n = m;
m = 1;
end
c = comb_recs(m,n,r);
function c = comb_recs(m,n,r)
if (n-m+1) < r
c = [];
return;
end
if r == 1
c = (m:n)';
return;
end
nCr = factorial(n-m+1)/(factorial(r)*factorial(n-m+1-r));
c = zeros(nCr,r);
cstart = 1;
for k = m:(n-r+1)
Csub = combination((k+1),n,(r-1));
cend = cstart+size(Csub,1)-1;
c(cstart:cend,1) = k;
c(cstart:cend,2:r) = Csub;
cstart = cend+1;
end
end
end
|
|
Contact us