You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: stereo3.m
    path of file: ./repos/jigsaw-matlab/tools/geom_util
    
    the code of the file until where you have to start completion: function [XPOS,YPOS,SCAL] = ...
        stereo3(rrad,xpos,ypos,xmid,ymid,kind)
%STEREO3 three-dimensional stereographic projection.
%   [XNEW,YNEW] = STEREO3(RRAD,XPOS,YPOS,XMID,YMID) returns
%   the stereographic projection [XNEW,YNEW] of the lat-lon
%   points [RRAD,XPOS,YPOS], where RRAD is the radius of the
%   sphere, and [XPOS,YPOS] are arrays of longitude and
%   latitude, respectively. Angles are measured in radians.
%   [XMID,YMID] are the lon-lat coordinates that the mapping
%   is 'centred' about. The stereographic projection is a
%   conformal mapping; preserving angles.
%
%   [XNEW,YNEW] = STEREO3(..., KIND) specifies the direction
%   of the mapping. KIND = 'FWD' defines a forward mapping,
%   and KIND = 'INV' defines an inverse mapping. Here, the
%   role of [XNEW,YNEW] and [XPOS,YPOS] are exchanged, with
%   [XPOS,YPOS] the stereographic coordinates, and
%   [XNEW,YNEW] the resulting lon-lat spherical angles.
%
%   [... ,SCAL] = STEREO3(...) also returns the scale-factor
%   associated with the forward mapping. This array stores

    
function [XPOS,YPOS,SCAL] = ...
        stereo3(rrad,xpos,ypos,xmid,ymid,kind)
%STEREO3 three-dimensional stereographic projection.
%   [XNEW,YNEW] = STEREO3(RRAD,XPOS,YPOS,XMID,YMID) returns
%   the stereographic projection [XNEW,YNEW] of the lat-lon
%   points [RRAD,XPOS,YPOS], where RRAD is the radius of the
%   sphere, and [XPOS,YPOS] are arrays of longitude and
%   latitude, respectively. Angles are measured in radians.
%   [XMID,YMID] are the lon-lat coordinates that the mapping
%   is 'centred' about. The stereographic projection is a
%   conformal mapping; preserving angles.
%
%   [XNEW,YNEW] = STEREO3(..., KIND) specifies the direction
%   of the mapping. KIND = 'FWD' defines a forward mapping,
%   and KIND = 'INV' defines an inverse mapping. Here, the
%   role of [XNEW,YNEW] and [XPOS,YPOS] are exchanged, with
%   [XPOS,YPOS] the stereographic coordinates, and
%   [XNEW,YNEW] the resulting lon-lat spherical angles.
%
%   [... ,SCAL] = STEREO3(...) also returns the scale-factor
%   associated with the forward mapping. This array stores
%   the relative length distortion induced by the projection
%   for all points in [XNEW,YNEW].

%-----------------------------------------------------------
%   Darren Engwirda : 2017 --
%   Email           : d.engwirda@gmail.com
%   Last updated    : 03/05/2018
%-----------------------------------------------------------

    if (nargin < +6), kind = 'fwd'; end