
function C = k_function(loc,area,b,extent)

% K_FUNCTION computes the k-Function for a point pattern
%            and plots the normalized L-Function (without 
%            edge corrections)

% Written by: TONY E. SMITH, 11/26/01

% INPUTS:
%     (i)   loc  = file of locations (xi,yi), i=1..m
%     (ii)  area = area of region
%     (iii)  b    = number of bins to use in CDF (and plot)
%     (iv) extent = 1 if max h = half of max pairwise distance (typical case)
%                 = 2 if max h = max pairwise distance to be considered
%
% DATA OUTPUTS: C = (1:b) vector containing raw Point Count
% SCREEN OUTPUTS:  Plot of L-Function over the specified extent.

% Compute Pairwise Distances

DD = dist_vec(loc);


% Compute Dmax

Dmax = max(DD);

if extent == 1
   
   Dmax = Dmax/2;
   
end


%Raw Count of Points

C = count(loc,b,Dmax);


%Normalize Counts

[n,junk] = size(loc);

lam = n/area;

H = Dmax*[1:b]/b;

K = (1/lam)*(1/n)*C;

L = sqrt(K/pi) - H;

plot(H,L,'LineWidth',2);

hold on;

plot(H,zeros(b,1),':k','LineWidth',1.5);




