GLTree Matlab Example: Cuboid Search Function
February 15, 2010 by Luigi Giaccari 
Filed under: Algorithms, Computational Geometry, Optimization
Leave a Comment
Filed under: Algorithms, Computational Geometry, Optimization
Leave a Comment
CuboidSearch2D query a GL-Tree for Points inside a cuboid
SYNTAX
idc=CuboidSearch(p,cuboid,ptrtree)
INPUT PARAMETERS
- p: [3xN] double array coordinates of reference points
- cuboid: [xmin;xmax;ymin;ymax]; 4×1 double array defining the cuboid boundary
- ptrtree: a pointer to the previously constructed GLtree.Warning if the pointer is uncorrect it will cause a crash, there is no way to check this in the mex routine, you have to check it in your script.
OUTPUT PARAMETERS
- idc: [?x1] column vector, each rows contains an index of a point found in the range described by the cuboid.
GENERAL INFORMATIONS
-Conditions for a point to be found in the radius is <=, so
points with distance from the query=r will be returned.
For question, suggestion, bug reports
giaccariluigi@msn.com
EXAMPLE
N=300;%reference points Cuboid=[.2 ,.5 ,.2 ,.5 ]'; p=rand(N,2);%reference points fprintf('RANDOM POINTS GENERATED\n\n') fprintf('BUILDING THE DATA STRUCTURE:\n') tic ptrtree=BuildGLTree2D(p'); fprintf('\tGLTree built in %4.4f s\n\treturned pointer %4.0f:\n\n',toc,ptrtree); fprintf('START CUBOID SEARCH:\n') tic [idc]=CuboidSearch2D(p',Cuboid,ptrtree); fprintf('\t %4.0f Points found in range\n\n',length(idc)); fprintf('DELETING THE TREE\n\n') DeleteGLTree2D(ptrtree); fprintf('TEST SUCCESFULLY COMPLETED !!!\n\n') %plot the NNG figure(1) title('Cuboid Search','fontsize',14); axis equal hold on x=[Cuboid(1),Cuboid(1),Cuboid(2),Cuboid(2),Cuboid(1)]; y=[Cuboid(3),Cuboid(4),Cuboid(4),Cuboid(3),Cuboid(3)]; h1=plot(p(:,1),p(:,2),'g.'); h2=plot(x,y,'b-'); h3=plot(p(idc,1),p(idc,2),'r.'); legend([h1,h2,h3],'Reference points','Cuboid','Inside points');
Popularity: 1% [?]
Related Posts
Comments
Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!
Include MATLAB code in your comment by doing the following:
<pre lang="MATLAB">
%insert code here
</pre>



















































