function [diameter, l,m] = diameter3d(M)
% Finds the diameter of a 3d object (at its widest), and returns that value.
% Really, this finds the longest inter-individual point distance.

currentMax = 0;
    j=0;
    
    for i=1:(size(M,1))
        for j=1:(size(M,1))
            if dist3d(M(i,2), M(i,3), M(i,4), M(j,2), M(j,3), M(j,4))>currentMax
                currentMax = dist3d(M(i,2), M(i,3), M(i,4), M(j,2), M(j,3), M(j,4));
		
		u = i;
		v = j;
            end
        end
    end
    
        l = u;
	m = v;
 	 diameter = currentMax;
