function [xl,yl,udx,udy] = createPolyRay(polygon,pointIdx,edgeIdx,Radius,Direction)
%createPolyRay Create a ray from pointIdx along the direction of edgeIdx that can be used to find the intersection of a
%line segment with a polygon using psIntersect friendly format.
%Assumption the first and last point of polygon should be distinct.

%   Copyright 2022 The MathWorks, Inc.

start=polygon(pointIdx,:);

numEdges=size(polygon,1);
if(edgeIdx==length(polygon))
    vj=polygon(numEdges,:);
    vj_plus1=polygon(1,:);
else
    vj=polygon(edgeIdx,:);
    vj_plus1=polygon(edgeIdx+1,:);
end
dx=vj_plus1(1)-vj(1);
dy=vj_plus1(2)-vj(2);


%Return normalized slope.
[udx,udy]=uav.internal.coveragePlanner.findNormalizedSlope(dx,dy);

xl=[start(1);start(1)+Direction*Radius*udx];
yl=[start(2);start(2)+Direction*Radius*udy];


end

% LocalWords:  ps
