function [px py] = calculateNewXY(p1_seg, p2_seg, seg_dist, alpha)
%calculateNewXY FUNCTION calculates the new xy vertex location along the stream line
% this is the location where the transect will be drawn Xm from the
% previous transect
%   

conversion = 3.28083989501312;
% conversion= 3.2808399 %this is the old conversion

% find point coordinates along line "seg_dist" from p1
if(p1_seg(1) > p2_seg(1) && p1_seg(2) > p2_seg(2)),
px = p1_seg(1) - (seg_dist*conversion)*abs(cos(alpha));
py = p1_seg(2) - (seg_dist*conversion)*abs(sin(alpha)); 
end

if(p1_seg(1) < p2_seg(1) && p1_seg(2) > p2_seg(2)),
px = p1_seg(1) + (seg_dist*conversion)*abs(cos(alpha));
py = p1_seg(2) - (seg_dist*conversion)*abs(sin(alpha)); 
end

if(p1_seg(1) > p2_seg(1) && p1_seg(2) < p2_seg(2)),
px = p1_seg(1) - (seg_dist*conversion)*abs(cos(alpha));
py = p1_seg(2) + (seg_dist*conversion)*abs(sin(alpha)); 
end

if(p1_seg(1) < p2_seg(1) && p1_seg(2) < p2_seg(2)),
px = p1_seg(1) + (seg_dist*conversion)*abs(cos(alpha));
py = p1_seg(2) + (seg_dist*conversion)*abs(sin(alpha)); 
end
  
%if the slope is 0 (y values are the same so rise / run is 0/x))
if(p1_seg(1) > p2_seg(1) && p1_seg(2)== p2_seg(2)),
px = p1_seg(1) - (seg_dist*conversion);
py = p1_seg(2); 
end

if(p1_seg(1) < p2_seg(1) && p1_seg(2) == p2_seg(2)),
px = p1_seg(1) + (seg_dist*conversion);
py = p1_seg(2); 
end

%if the slope is 0 (x values are the same so rise / run is x/0))
if(p1_seg(1) == p2_seg(1) && p1_seg(2) > p2_seg(2)),
px = p1_seg(1);
py = p1_seg(2) - (seg_dist*conversion); 
end

if(p1_seg(1) == p2_seg(1) && p1_seg(2) < p2_seg(2)),
px = p1_seg(1);
py = p1_seg(2) + (seg_dist*conversion); 
end

end

