function [DIR, DIST] = segmentToRay(ORIGIN, ENDPT)
% segmentToRay Converts segments to rays with distances.
%
%	[DIR, DIST] = segmentToRay(ORIGIN, ENDPT) converts segments specified
%	by ORIGIN and ENDPT to rays specified by ORIGIN, DIR, and DIST. ORIGIN
%	is an n-by-3 or 1-by-3 matrix corresponding to the starting points of
%	the segment or ray. ENDPT is an n-by-3 matrix corresponding to the
%	ending points of the segment. DIR is an n-by-3 matrix of normalized
%	direction vectors between ORIGIN and ENDPT. DIST is an n-by-1 matrix of
%	distances between ORIGIN and ENDPT.
%
%	This function is for internal use. The interface and existence of this
%	function is subject to change in future releases.
%
%	See also matlabshared.internal.StaticSceneRayTracer

%	Copyright 2020-2021 The MathWorks, Inc.

arguments
    ORIGIN (:,3) {mustBeNumeric, mustBeReal, mustBeFinite}
    ENDPT (:,3) {mustBeNumeric, mustBeReal, mustBeFinite}
end

DIR = ENDPT - ORIGIN;
DIST = sqrt(sum(DIR.^2, 2));
DIR = DIR ./ DIST;
DIR(isnan(DIR)) = 0;
end
