function[pn_perp_pos pn_perp_neg] = calculatePointsAlongLine(startingPoint,numberOfSamples,slope,samplingDistance,avWidth)

%this code calculate points at a given distance (samplingDistance) along a
%line beginning at a starting point and moving outwards. if Type =2
%then it calculates the points inwards (IE from the edge of the buffer
%inwards)

%inputs = slope of (perpendicular to stream) line [m_perp] and slope in
%radians (alpha_perp)

%-----------------------BEGIN turn this on if i want to test as a non function 
%{
clear
samplingDistance=1;
numberOfSamples=200; % number of samples to be taken along the transect in each direction
slope=-.4; %slope of the line
load B
startingPoint=B;
avWidth=30;
type=1; %1=sample from the stream out to the edge
%2 = sample from the edge back towards the stream
%}
%-----------------------END turn this on if i want to test as a non function 


%perp_seg=samplingDistance; %distance b/w points along line
% convert to radians
%alpha_perp(j) = atan(m_perp(j)); 
slopeRadians = atan(slope(1));
perp_seg = samplingDistance; %distance b/w points along line
widthAdjustment = ((avWidth*3.2808399 )/2); %account for the width of the stream and begin sampling at or close to the end of the stream
% in the positive direction

for i = 1:numberOfSamples
    %for i=1:1
    % conversion to feet (as the xy values are in state plane feet) and
    % multiply by i (the sample point number)
    sampleDist = (i*3.2808399);
  
      
 
    %if this is the first sample, then make sure to begin at the stream
    %edge (ie at the 1/2 average width location)
  
        
%     mm=(perp_seg*sampleDist);
%     disp(perp_seg)
% disp(mm)
    
    
     if slope(1)==0
      % in the positive direction
       px_perp_pos = startingPoint(1) ;
       py_perp_pos = startingPoint(2)+ ((perp_seg*sampleDist)+widthAdjustment);
       
     % in the negative direction
       px_perp_neg = startingPoint(1);
       py_perp_neg = startingPoint(2) - ((perp_seg*sampleDist)+widthAdjustment); 
     end
     
    %check to see if slope is Nan
    if isnan(slope(1))  %this means that slope = x/0 = nan (only vertical)
        %however because thsi is the slope of the original stream line i
        %should adjust the X values because the transect perpendicular to the stream will run
        %horizontal
   
    % in the positive direction
       px_perp_pos = startingPoint(1)+ ((perp_seg*sampleDist)+widthAdjustment);
       py_perp_pos = startingPoint(2);
       
     % in the negative direction
       px_perp_neg = startingPoint(1) - ((perp_seg*sampleDist)+widthAdjustment); 
       py_perp_neg = startingPoint(2);
    end
    
    % this code is for sampling from the edge of the stream out to the 
    % edge of the buffer  (to calculate width)
    if(slope(1) > 0),
        px_perp_pos = startingPoint(1) + ((perp_seg*sampleDist)+widthAdjustment)*cos(slopeRadians);
        py_perp_pos = startingPoint(2) + ((perp_seg*sampleDist)+widthAdjustment)*sin(slopeRadians);

        % in the negative direction
        px_perp_neg = startingPoint(1) - ((perp_seg*sampleDist)+widthAdjustment)*cos(slopeRadians);
        py_perp_neg = startingPoint(2) - ((perp_seg*sampleDist)+widthAdjustment)*sin(slopeRadians);
    end

    % in the positive direction
    if(slope(1)<0)
    px_perp_pos = startingPoint(1) - ((perp_seg*sampleDist)+widthAdjustment)*cos(slopeRadians); %changed these to fix transect pepr angles...not sure it's right
    py_perp_pos = startingPoint(2) - ((perp_seg*sampleDist)+widthAdjustment)*sin(slopeRadians);

    % in the negative direction
    px_perp_neg = startingPoint(1) + ((perp_seg*sampleDist)+widthAdjustment)*cos(slopeRadians);
    py_perp_neg = startingPoint(2) + ((perp_seg*sampleDist)+widthAdjustment)*sin(slopeRadians);
    end
%

% coordinate of point = seg_dist
%1=positive
%0=negative
distanceOut=(i*samplingDistance);
pn_perp_pos(i,:) = [1 distanceOut px_perp_pos py_perp_pos];
pn_perp_neg(i,:) = [0 distanceOut px_perp_neg py_perp_neg];

end


%{

%plot out everything to see how this works

plot(pn_perp_pos(1:end,3),pn_perp_pos(1:end,4),'r*'), hold on
plot(pn_perp_neg(1:end,3),pn_perp_neg(1:end,4),'b*'), hold on
plot(startingPoint(1),startingPoint(2),'g*'), hold on
%plot()
axis equal
%}
