Hi c. It may be that there is a difference. I cannot fully understand the way you use the ismember function. To me, it looks you are comparing a matrix with integer numbers (the triangle vertices) against a logical matrix with 1's where the vertex of a triangle is inside the region or in the border. I just read the help of ismember and this will just give you the triangles that have the vertex "1". Am I right? Here a simplified example
% an abstract triangulation in your format A = [1 2 3; 2 4 3; 4 5 3]'; % the result of the distance test: vertex 3 and 1 are inside the region res = [1 0 1 0 0]; B = reshape(ismember(A,res),3,3) B = 1 0 0 0 0 0 0 0 0 then the operation the functions "all" and "find" give find(all(B)) ans = [](1x0) However, now that I now the function "ismember" I may think of a use to it! Thanks a lot. I been checking the package mesh, it is pretty nice, but for my objective, I would be force to create the .geo description of my region (right?)...which is the result of a nonlinear mapping on the unit hemisphere... no really easy, jeje. I am trying to merge alpha shapes from CGAL or some functions from iso2mesh to get good meshes on these deformed spherical sections; relying only on sampled points on the region and its border. Thanks again JPi On Thu, Oct 21, 2010 at 2:50 PM, c. <carlo.defa...@gmail.com> wrote: > > Hi, > > On 21 Oct 2010, at 13:25, JuanPi wrote: > >> Hi c. >> >> Thanks a lot for the pointer. Indeed I am working with triangular meshes. >> >> In my experience dealing with cells is very slow, so I try to avoid them. >> >> I need this function to speed up queries to a mesh (maybe there is a >> better solution), with a cost on memory and preprocessing. I use the >> point2triag matrix to slice(or clip) the mesh to the region of >> interest, and then do the usual call to inpolygon (or tsearch, though >> I found it slow) in the clipped mesh. >> This use of the matrix requires fast slicing, and I wonder if a cell >> would be slower... >> example >> Given a extremely dense mesh "T" of the square [0 1] and Nx2 nodes >> coordinates "coord". >> Given points "xi" in a circle of radius 0.1 and center c=[0.5,0.5] >> To get the triangles they belong to I would do >> >> p2T = point2triag(T); >> idx = find( sumsq( coord-repmat(c,N,1),2) <= (0.1)^2) >> triangles = p2T(idx,:); > > If I understand correctly, what you need to do is find all triangles whos > vertices are all > within a distance d = 0.1 from a point c = [xc, yc]. > I'm not sure whether my approach is faster than yours but what I usually do > when I need something like that is: > > triangles = find (all (ismember (t (1:3, :), (p(1,:) - xc).^2 + (p(2,:) - > yc).^2 <= d^2))); > > this is untested but should work in Ocatve 3.3+, while in 3.2.4 I seem to > recall you would need a reshape to work around a bug in ismember: > > triangles = find (all (reshape (ismember (t (1:3, :), (p(1,:) - xc).^2 + > (p(2,:) - yc).^2 <= d^2), size(t(1:3,:))))); > > note that I have vertex coordinates in a 2 x nvertex matrix p and triangle > veritces in the first 3 rows of a 4 x ntriangles matrix t, so I think p = > coord' and T' = t (1:3, :). > >> While with a cell, I think, it wont be so easy. Please correct me if I >> am wrong, I love the functionalities of cells, but at the moment I >> need speed! Maybe a sparse matrix would be another option, but I have >> no clue how sparse are the matrix created this way. >> >> Also, note that point2triag internally calculates the maximum degree >> of your mesh and erases the extra columns (filled with NaNs) at the >> end. >> >> I will be happy to contribute with the functionality, provided my code >> is somehow efficient. > > even though I wouldn't use it in the case above, I believe point2triag would > be a nice addition to msh, > why do you say a cell-array is slower in this case, do you have an example > benchmark? > >> Thanks, >> >> JPi > > > c. > > > -- JuanPi Carbajal ----- A neutron walks into a bar and orders a drink. It asks the bartender, "How much?", the bartender answers, "For you, sir, no charge." ----- www.ailab.ch/carbajal ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ Octave-dev mailing list Octave-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/octave-dev