% Function for detecting an object within an given area % % result = rubberband(geometrie,[ x, y, z]) % % geometrie = geometry % xyz = bounds of the rubberband x,y,z-coordiantes % % result = vertex/vertices bounded by the given coordinates function result = vertex(geometry,x,y,z,tol) % getting geometry dimension [gd] = geominfo(geometry,'out',{'gd'}); % getting geometrie infos : number of objects (for every space dimension) [no] = geominfo(geometry,'out',{'no'},'od',0:gd); % plot geometrie for control purposes figure, geomplot(geometry,'pointlabels','on'); % if tol does not exist, set it to eps if exist('tol','var') ~= 1 tol = eps; end % get all points of this geometry [xyz]=flgeomvtx(geometry); % Alternative procedure % Creating Entities Matrix % Bm = [1:no(1)]; % % creating search parameter % Par = {Bm}; % % getting coordinates for every element % [xyz] = geominfo(geometry,'out',{'xx'},'par',Par); %% Calculating the X-Coordinates within the rubberband % getting elements with x-coordinate > x element_x_g = ceil(find(xyz(1,:) + tol >= x(1))); % getting elements with x-coordinate < x element_x_s = ceil(find(xyz(1,:) <= x(2) + tol)); % creating a matrix for the elements greater x coordinate_matrix_x_g = zeros(1,no(1)); % creating a matrix for the elements smaller x coordinate_matrix_x_s = zeros(1,no(1)); % filling the matrix with a one when element fullfills the condition > x coordinate_matrix_x_g(element_x_g) = 1; % filling the matrix with a one when element fullfills the condition < x coordinate_matrix_x_s(element_x_s) = 1; % Merge the x-coordinate_s and x-coordinate_g matrix coordinate_matrix_x = coordinate_matrix_x_g & coordinate_matrix_x_s; %% Calculating the Y-Coordinates % getting elements with y-coordinate > y element_y_g = ceil(find(xyz(2,:) +tol >= y(1))); % getting elements with y-coordinate < y element_y_s = ceil(find(xyz(2,:) <= y(2) + tol)); % creating a matrix for the elements greater y coordinate_matrix_y_g = zeros(1,no(1)); % creating a matrix for the elements smaller y coordinate_matrix_y_s = zeros(1,no(1)); % filling the matrix with an one when element fullfills the condition > y coordinate_matrix_y_g(element_y_g) = 1; % filling the matrix with an one when element fullfills the condition < y coordinate_matrix_y_s(element_y_s) = 1; % Merge the y-coordinate_s and y-coordinate_g matrix coordinate_matrix_y = coordinate_matrix_y_g & coordinate_matrix_y_s; %% Z - Coordinate if length(no) == 4 % getting elements with z-coordinate > z element_z_g = ceil(find(xyz(3,:) + tol >= z(1))); % getting elements with z-coordinate < z element_z_s = ceil(find(xyz(3,:) <= z(2) +tol)); % creating a matrix for the elements greater z coordinate_matrix_z_g = zeros(1,no(1)); % creating a matrix for the elements smaller z coordinate_matrix_z_s = zeros(1,no(1)); % filling the matrix with an one when element fullfills the condition > z coordinate_matrix_z_g(element_z_g) = 1; % filling the matrix with an one when element fullfills the condition < z coordinate_matrix_z_s(element_z_s) = 1; % Merge the z-coordinate_s and z-coordinate_g matrix coordinate_matrix_z = coordinate_matrix_z_g & coordinate_matrix_z_s; end %% Calculating the Object which fullfills all the conditions x y z % Addition of both matrices to get the element which is the searchobject if length(no) == 4 result{1} = find(coordinate_matrix_x & coordinate_matrix_y & coordinate_matrix_z == 1); else result{1} = find(coordinate_matrix_x & coordinate_matrix_y == 1); end % creating empty result_tmp matrix result_tmp = []; % getting the lentth of the results length_result1 = length(result{1}); % build a matrix with the coordinates of the found entities if length(no) == 4 result_tmp = [[xyz( 1, result{1})];[xyz( 2, result{1})];[xyz( 3, result{1})]]; else result_tmp = [[xyz( 1, result{1})];[xyz( 2, result{1})]]; end % hand over the result coordinates to the output parameter result result{2} = result_tmp;