function perim_points = perim(data) %------------------------------------------------------------------------------------------ %****************************** PROGRAM EXPLANATION PERIM.m ******************************* % PERIM.m calculates points along the outter walls of the cave making a polygon cross- % section at each survey station. The polygons are made by interpolating points along % four lines, two connecting the top of the cave with the right and left walls and two % connecting the bottom of the cave with the right and left walls. % Input to PERIM.m is provided by EXPAND.m. Output from PERIM.m consists of three ascii % data files (allpts.txt, toppts.txt, and botpts.txt) and a three-dimensional plot of the % points describing the cave. Allpts.txt contains all of the (x,y,z) points describing % the cave system. Toppts.txt and botpts.txt respectively contain (x,y,z) points % describing the top and bottom halves of the cave system. %------------------------------------------------------------------------------------------ %********************* DETERMINING THE SIZE OF THE INPUT DATA MATRIX ********************** [row,col] = size(data); % extracting data from the input matrix x = data(:,2); y = data(:,3); z = data(:,4); ztop = data(:,5); zbot = data(:,6); room = data(:,7); xrtw = data(:,8); yrtw = data(:,9); xltw = data(:,10); yltw = data(:,11); %------------------------------------------------------------------------------------------ %******************************* INITALIZING VARRIABLES *********************************** % setting inital values for the matrices *_perim and *_trans that will contain all % perimeter and transect (x,y,z) coordinates. The inital values will be eliminated from % the final data set. XTOP_perim = 0; YTOP_perim = 0; ZTOP_perim = 0; XBOT_perim = 0; YBOT_perim = 0; ZBOT_perim = 0; xhorz = 0; yhorz = 0; zhorztop = 0; zhorzbot = 0; xverttop = 0; yverttop = 0; zverttop = 0; xvertbot = 0; yvertbot = 0; zvertbot = 0; %------------------------------------------------------------------------------------------ %********************* LOOPING OVER THE SET OF INPUT SURVEY STATIONS ********************** count = 1; for i = 1:row if x(i) ~=-999.9 xx(count) = x(i); yy(count) = y(i); zz(count) = z(i); xxrtw(count) = xrtw(i); yyrtw(count) = yrtw(i); xxltw(count) = xltw(i); yyltw(count) = yltw(i); zztop(count) = ztop(i); zzbot(count) = zbot(i); % checking to see if the survey station lies in a large room where the variable "room" = 0 % if not in a large room and 1 if in a large room. "Room" must be included in the % original data set. if room(i) == 0 % case for survey stations not in a large room. % sets a 10 point increment from the top and bottom of the cave to the right and left % walls along the x, y, and z axes. % points in the (x,y) planes step away from the survey point. % points in the (x,z) planes step toward the survey point. xincrt = (xrtw(i) - x(i)) / 10; xinclt = (xltw(i) - x(i)) / 10; yincrt = (yrtw(i) - y(i)) / 10; yinclt = (yltw(i) - y(i)) / 10; zinctop = (ztop(i) - z(i)) / 10; zincbot = (zbot(i) - z(i)) / 10; % setting inital values for the perimeter point variables. xrt_perim = x(i); yrt_perim = y(i); xlt_perim = x(i); ylt_perim = y(i); ztop_perim = ztop(i); zbot_perim = zbot(i); % starting internal loop to calculate perimeter points. for j = 2:10 % calculating the x,y coordinates from the top and bottom to the right and left sides. xrt_perim = xrt_perim + xincrt; yrt_perim = yrt_perim + yincrt; xlt_perim = xlt_perim + xinclt; ylt_perim = ylt_perim + yinclt; % calculating the z coordinates from the right and left sides to the top and bottom. ztop_perim = ztop_perim - zinctop; zbot_perim = zbot_perim - zincbot; % filling the data matrices XTOP_perim = [XTOP_perim xrt_perim xlt_perim]; YTOP_perim = [YTOP_perim yrt_perim ylt_perim]; ZTOP_perim = [ZTOP_perim ztop_perim ztop_perim]; XBOT_perim = [XBOT_perim xrt_perim xlt_perim]; YBOT_perim = [YBOT_perim yrt_perim ylt_perim]; ZBOT_perim = [ZBOT_perim zbot_perim zbot_perim]; end else % case for survey stations inside a large room. % defining step increments for horizontal (horz) and vertical (vert) lines making a square % around the room. xhorzinc = (xltw(i) - xrtw(i)) / 10; yhorzinc = (yltw(i) - yrtw(i)) / 10; ztopinc = (ztop(i) - z(i)) / 5; zbotinc = (z(i) - zbot(i)) / 5; % setting inital values. xhorz_perim = xxrtw; yhorz_perim = yyrtw; ztop_perim = z(i); zbot_perim = z(i); % starting internal loop to calculate perimeter points. for j = 2:11 % stepping across the room from right to left to make the (x,y) coordinates for the top % and bottom transects across the room. xhorz_perim = xhorz_perim + xhorzinc; yhorz_perim = yhorz_perim + yhorzinc; % filling the top and bottom coordinate vectors excluding the last point which would be a % duplicate point calculated in the vertical transect. if j < 11 xhorz = [xhorz xhorz_perim]; yhorz = [yhorz yhorz_perim]; zhorztop = [zhorztop ztop(i)]; zhorzbot = [zhorzbot zbot(i)]; end % stepping across the room from bottom to top to make the z coordinates for the right and % left transects across the room. % calculating the top and bottom parts of the right and left vertical transects. if j < 7 ztop_perim = ztop_perim + ztopinc; % filling the right and left coordinate vectors. xverttop = [xverttop xrtw(i) xltw(i)]; yverttop = [yverttop yrtw(i) yltw(i)]; zverttop = [zverttop ztop_perim ztop_perim]; else zbot_perim = zbot_perim - zbotinc; % filling the right and left coordinate vectors. xvertbot = [xvertbot xrtw(i) xltw(i)]; yvertbot = [yvertbot yrtw(i) yltw(i)]; zvertbot = [zvertbot zbot_perim zbot_perim]; end end end end end % determining the size of the perimeter coordinate matrices. [rowh,colh] = size(xhorz); [rowv,colv] = size(xverttop); [rowa,cola] = size(XTOP_perim); %------------------------------------------------------------------------------------------ %*************************** CREATING THE FINAL OUTPUT MATRICES *************************** xtop_half = [xx' xxrtw' xxltw' XTOP_perim(2:cola) xhorz(2:colh) xverttop(2:colv)]; ytop_half = [yy' yyrtw' yyltw' YTOP_perim(2:cola) yhorz(2:colh) yverttop(2:colv)]; ztop_half = [zztop' zz' zz' ZTOP_perim(2:cola) zhorztop(2:colh) zverttop(2:colv)]; xbot_half = [xx' xxrtw' xxltw' XBOT_perim(2:cola) xhorz(2:colh) xvertbot(2:colv)]; ybot_half = [yy' yyrtw' yyltw' YBOT_perim(2:cola) yhorz(2:colh) yvertbot(2:colv)]; zbot_half = [zzbot' zz' zz' ZBOT_perim(2:cola) zhorzbot(2:colh) zvertbot(2:colv)]; top_half = [xtop_half' ytop_half' ztop_half']; bot_half = [xbot_half' ybot_half' zbot_half']; allpts = [top_half' bot_half']'; %------------------------------------------------------------------------------------------ %************************************ SAVING DATA ***************************************** save toppts.txt top_half -ascii -tabs save botpts.txt bot_half -ascii -tabs save allpts.txt allpts -ascii -tabs %------------------------------------------------------------------------------------------ %******************************** PLOTTING DATA IN 3-D ************************************ disp(' ') disp(' The new data has been saved in three files to the current') disp(' directory: allpts.txt containing all the new points,') disp(' toppts.txt containing data for the top half of the cave, and') disp(' botpts.txt containing data for the bottom half of the cave.') disp(' ') disp(' ') plotchk = input(' Do you want to plot any points? [Y/N]','s'); if isempty(plotchk) plotchk = 'Y'; end if plotchk == 'y' plotchk = 'Y'; end if plotchk == 'Y' figure while plotchk == 'Y' clc disp(' ') disp(' ') disp(' ') disp(' Select data you want to see: [a] - all points ') disp(' [b] - top half of the cave ') disp(' [c] - bottom half of the cave ') disp(' ') disp(' ') disp(' ') selection = input(' Enter your selection ','s'); if selection == 'a' xx = allpts(:,1); yy = allpts(:,2); zz = allpts(:,3); plot3(xx,yy,zz,'c+') end if selection == 'b' xx = top_half(:,1); yy = top_half(:,2); zz = top_half(:,3); plot3(xx,yy,zz,'c+') end if selection == 'c' xx = bot_half(:,1); yy = bot_half(:,2); zz = bot_half(:,3); plot3(xx,yy,zz,'c+') end disp(' ') disp(' ') plotchk = input('Do you want to view another selection? Y/N [Y] ','s'); if isempty(plotchk) plotchk = 'Y'; end if plotchk == 'y' plotchk = 'Y'; end end end %------------------------------------------------------------------------------------------ %*************** CREATING MATRICES CONTAINING ONLY THE PERIMETER POINTS ******************* xtop_perim = [XTOP_perim(2:cola) xhorz(2:colh) xverttop(2:colv)]; ytop_perim = [YTOP_perim(2:cola) yhorz(2:colh) yverttop(2:colv)]; ztop_perim = [ZTOP_perim(2:cola) zhorztop(2:colh) zverttop(2:colv)]; xbot_perim = [XBOT_perim(2:cola) xhorz(2:colh) xvertbot(2:colv)]; ybot_perim = [YBOT_perim(2:cola) yhorz(2:colh) yvertbot(2:colv)]; zbot_perim = [ZBOT_perim(2:cola) zhorzbot(2:colh) zvertbot(2:colv)]; perim_points = [xtop_perim' ytop_perim' ztop_perim' xbot_perim' ybot_perim' zbot_perim']; %------------------------------------------------------------------------------------------ %******************************* END OF PROGRAM PERIM.m ***********************************