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: NanTolDistTri2Pnt.m
    path of file: ./repos/CutAndDisplace/3dCode/SimpleExternalFunctions
    
    the code of the file until where you have to start completion: function [X,Y,Z]=NanTolDistTri2Pnt( X,Y,Z,P1,P2,P3,MidPoint,FaceNormalVector,Distance )
% DistTri2Pnt: Nans points within a set distance of a triangle. Works for
%                   multiple triangles and input points.
%
%               
% usage #1:
% [X,Y,Z]=NanTolDistTri2Pnt( X,Y,Z,P1,P2,P3,MidPoint,FaceNormalVector,Distance )
%
%
% Arguments: (input)
%    X,Y,Z         - The query points that will be set to NAN if within
%                    the distance.
%
%  MidPoint        - The x, y and Z locations of each triangles midpoint
%                   [x,y,z]. 
%
% P1,P2,P3          - n*3 Column vector where each 'P' represents the
%                    different corner points of one of the triangles (XYZ).
%                    Not as efficient in terms of storage but easier to
%                    understand.
%
% FaceNormalVector  - The normal vectors n*3, (CosAx,CosAy,CosAz) of each
%                    triangle.
%
% Distance         - Set distance around each line segment that is removed.
%                   
%
%
%
% Arguments: (output)
%    X,Y,Z           - The query points that will have been set to NAN if within
%                    the distance.
%
%
% Example usage:
%
% N/A.
%
%  Author: Tim Davis
%  Copyright 2017, Tim Davis, Potsdam University\The University of Aberdeen


for i = 1:numel(P1(:,1))
    
    %Vector from midpoint to Tris P1
    Mid2P1=normr([(P1(i,1)-MidPoint(i,1)),...
                  (P1(i,2)-MidPoint(i,2)),...
                  (P1(i,3)-MidPoint(i,3))]);
    %Amount we move P1 out:          
    NewP1Offset=[Mid2P1(1).*Distance,Mid2P1(2).*Distance,Mid2P1(3).*Distance];
    
    P1(i,:)=P1(i,:)+NewP1Offset;
    
    %Vector from midpoint to Tris P2
    Mid2P2=normr([(P2(i,1)-MidPoint(i,1)),...
                  (P2(i,2)-MidPoint(i,2)),...
                  (P2(i,3)-MidPoint(i,3))]);
    %Amount we move P2 out:          
    NewP2Offset=[Mid2P2(1).*Distance,Mid2P2(2).*Distance,Mid2P2(3).*Distance];
    
    P2(i,:)=P2(i,:)+NewP2Offset;    
    
    PointsLst=[P1(i,:),P2(i,:),P3(i,:)];
    Seperation=[FaceNormalVector(i,1).*Distance,FaceNormalVector(i,2).*Distance,FaceNormalVector(i,3).*Distance];

        %Vector from midpoint to Tris P3
    Mid2P3=normr([(P3(i,1)-MidPoint(i,1)),...
                  (P3(i,2)-MidPoint(i,2)),...
                  (P3(i,3)-MidPoint(i,3))]);
    %Amount we move P3 out:          
    NewP3Offset=[Mid2P3(1).*Distance,Mid2P3(2).*Distance,Mid2P3(3).*Distance];
    
    P3(i,:)=P3(i,:)+NewP3Offset;
    
    %Start axis lims
    %The triangles after being seperated by chonsen amount
    [PointsNew2P]=DisplaceTris2(PointsLst,Seperation);
    [PointsNew2N]=DisplaceTris2(PointsLst,-Seperation);

    %Create an alpha shape around the points. 
    shp = alphaShape([PointsNew2P(:,1);PointsNew2N(:,1)],...
        [PointsNew2P(:,2);PointsNew2N(:,2)],...
        [PointsNew2P(:,3);PointsNew2N(:,3)],1E9);
     %Drawing if wanted: 
     %figure;
     %plot(shp);  hold on
     %scatter3(X(:),Y(:),Z(:),'.k')
    
    X=X(:);
    Y=Y(:);
    Z=Z(:);

    
function [X,Y,Z]=NanTolDistTri2Pnt( X,Y,Z,P1,P2,P3,MidPoint,FaceNormalVector,Distance )
% DistTri2Pnt: Nans points within a set distance of a triangle. Works for
%                   multiple triangles and input points.
%
%               
% usage #1:
% [X,Y,Z]=NanTolDistTri2Pnt( X,Y,Z,P1,P2,P3,MidPoint,FaceNormalVector,Distance )
%
%
% Arguments: (input)
%    X,Y,Z         - The query points that will be set to NAN if within
%                    the distance.
%
%  MidPoint        - The x, y and Z locations of each triangles midpoint
%                   [x,y,z]. 
%
% P1,P2,P3          - n*3 Column vector where each 'P' represents the
%                    different corner points of one of the triangles (XYZ).
%                    Not as efficient in terms of storage but easier to
%                    understand.
%
% FaceNormalVector  - The normal vectors n*3, (CosAx,CosAy,CosAz) of each
%                    triangle.
%
% Distance         - Set distance around each line segment that is removed.
%                   
%
%
%
% Arguments: (output)
%    X,Y,Z           - The query points that will have been set to NAN if within
%                    the distance.
%
%
% Example usage:
%
% N/A.
%
%  Author: Tim Davis
%  Copyright 2017, Tim Davis, Potsdam University\The University of Aberdeen


for i = 1:numel(P1(:,1))
    
    %Vector from midpoint to Tris P1
    Mid2P1=normr([(P1(i,1)-MidPoint(i,1)),...
                  (P1(i,2)-MidPoint(i,2)),...
                  (P1(i,3)-MidPoint(i,3))]);
    %Amount we move P1 out:          
    NewP1Offset=[Mid2P1(1).*Distance,Mid2P1(2).*Distance,Mid2P1(3).*Distance];
    
    P1(i,:)=P1(i,:)+NewP1Offset;
    
    %Vector from midpoint to Tris P2
    Mid2P2=normr([(P2(i,1)-MidPoint(i,1)),...
                  (P2(i,2)-MidPoint(i,2)),...
                  (P2(i,3)-MidPoint(i,3))]);
    %Amount we move P2 out:          
    NewP2Offset=[Mid2P2(1).*Distance,Mid2P2(2).*Distance,Mid2P2(3).*Distance];
    
    P2(i,:)=P2(i,:)+NewP2Offset;    
    
    PointsLst=[P1(i,:),P2(i,:),P3(i,:)];
    Seperation=[FaceNormalVector(i,1).*Distance,FaceNormalVector(i,2).*Distance,FaceNormalVector(i,3).*Distance];

        %Vector from midpoint to Tris P3
    Mid2P3=normr([(P3(i,1)-MidPoint(i,1)),...
                  (P3(i,2)-MidPoint(i,2)),...
                  (P3(i,3)-MidPoint(i,3))]);
    %Amount we move P3 out:          
    NewP3Offset=[Mid2P3(1).*Distance,Mid2P3(2).*Distance,Mid2P3(3).*Distance];
    
    P3(i,:)=P3(i,:)+NewP3Offset;
    
    %Start axis lims
    %The triangles after being seperated by chonsen amount
    [PointsNew2P]=DisplaceTris2(PointsLst,Seperation);
    [PointsNew2N]=DisplaceTris2(PointsLst,-Seperation);

    %Create an alpha shape around the points. 
    shp = alphaShape([PointsNew2P(:,1);PointsNew2N(:,1)],...
        [PointsNew2P(:,2);PointsNew2N(:,2)],...
        [PointsNew2P(:,3);PointsNew2N(:,3)],1E9);
     %Drawing if wanted: 
     %figure;
     %plot(shp);  hold on
     %scatter3(X(:),Y(:),Z(:),'.k')
    
    X=X(:);
    Y=Y(:);
    Z=Z(:);
    in=zeros(numel(X),1);
    for k=1:numel(X)
        if isnan(X(k))
        else
        %Now check if point is within the bound: 
        if inShape(shp,X(k),Y(k),Z(k)) 
            in(k)=1;
        end