In-Polyhedron Test

August 14, 2009 by Luigi Giaccari 
Filed under: CAD, Computational Geometry, Graphics 
13 Comments
VN:F [1.8.8_1072]
Rating: 0 (from 2 votes)
VN:F [1.8.8_1072]
Rating: 10.0/10 (2 votes cast)

INPOlyedron2

InPolyedron detects points inside a manifold closed surface (even non convex ones). The normal orientation is assumed to be outwards. Warning there is no check for closed surface or normal orientation, open surfaces will give nonsense results.

In the limit of numerical accuracy, points lying on the surface will be considered in.

Usage

Input:

  • p:  points of the surface npx3 array
  • t: triangles indexes, first points flagged as one, ntx3 array
  • tnorm:  outward normals of traingles, ntx3 array
  • qp:  points to be queried, nqx3 array

Output:

  • in: nqx1 logical vector, true for in, false for out

Author: Giaccari Luigi
Created: 15/05/2009
e-mail: giaccariluigi@msn.com

Download Now

VN:F [1.8.8_1072]
Rating: 10.0/10 (2 votes cast)
VN:F [1.8.8_1072]
Rating: 0 (from 2 votes)
In-Polyhedron Test10.0102

Popularity: 12% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS

Related Posts

Comments

13 Comments on In-Polyhedron Test

  1. tolga on Fri, 16th Oct 2009 19:23
  2. hello.. this looks like a quite useful code…

    but there is a problem i cannot figure out.

    i have the parameters for a surface : triangles, points and normals.

    my problem starts here: the normals are not normals for triangles but they are normals at the points.

    however your function requires the normals for triangles. Is there a way to estimate the normals for triangles from the normals of the points, so that I can use your function?

    i will be so glad to hear your any possible solution for this.

    thank you in advance.

    [Reply]


    Luigi Giaccari Reply:

    To get the normals of triangles you don’t need to have normals in points.

    If you have Matlab R2009a you can use the computational geometry toolbox to get a conform outward normal for each triangle. There is a built in function.

    To get your own code you need to compute the nomral for one triangle (use cross product) and then perform a propagation on the neighborhood triangles keeping the orientation of normals. It is not the easiest thing but not even the most diffucult, try it and let me know.

    Luigi

    [Reply]

    UA:F [1.8.8_1072]
    Rating: 0.0/5 (0 votes cast)
    UA:F [1.8.8_1072]
    Rating: 0 (from 0 votes)
  3. Ajay on Mon, 29th Mar 2010 20:35
  4. Hi Luigi,

    I tried to use this algorithm to find points in a non convex shape and I get some extra points that lie outside the shape. I checked the normal of the facets and they seem to be ok (outward pointing). I have uploaded a screen shot of the points overlapped on the triangulated surface (points.bmp) and also an xls file (data.xls) which contains the vertices (columns A:C) and faces (columns E:G) in the following link. If you could take a look and give your comments that would be great.

    http://people.clarkson.edu/~sonarav/

    Thanks,
    Ajay

    [Reply]


    Luigi Giaccari Reply:

    That’s a numerical problem that comes form the presence of almost vertical facets.

    Run the algorithm this way and it should be ok:

     
    in1=InPolyedron_v3(p,t,tnorm,qp);
    id=[3 2 1]; 
    in2=InPolyedron_v3(p(:,id),t,tnorm(:,id),qp(:,id));
    id=[1 3 2]; 
    in3=InPolyedron_v3(p(:,id),t,tnorm(:,id),qp(:,id));
    in=in1&in2&in3;

    Luigi

    [Reply]


    Ajay Reply:

    Luigi,

    It works fine now. Thanks for your help.

    Ajay

    [Reply]

    UN:F [1.8.8_1072]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.8_1072]
    Rating: 0 (from 0 votes)
  5. María Herrojo Ruiz on Tue, 6th Apr 2010 15:27
  6. Hi Luigi,

    your code seems really nice. It works good with your examples. I would like to test it with some data I have from a brain structure (subthalamic nucleus) and with some empirical (query) points of the electrodes implanted (inside/outside would be the question).

    My problem is the following:

    I have the coordinates of the set of 3 points constituting each triangle:
    polyedron size [329x9] (3 points x 3D: 329 triangles).

    Because the original data, ist vtk, it also gives me the following triangles indices:
    triangles indices [1974x3]

    The problem is that, actually, I don’t know where the triangles indices come from, since they are already given in the original data.
    The indices [1974x3] I have seem not to work for trisurf, when I give the data points of the polyedron as [987x3]. MATLAB says “Faces values must be >= 1.0″.

    So, in order to test your method, do you have a suggestion to recompute from the original set of 3 points for each triangle the correct triangle indexes for your method?
    Given “p”, how do you compute “t”(tringle indices) and “tnorm”?

    Regarding the normal vectors to each triangle. It is easy to compute the normal to each triangle (cross product of two vectors constititung the triangle, then checking for the outward direction) and locating it, e.g. at the middle of the triangle or at any of its points. The I would have 1 normal vector for the surface of each triangle, right? Or do I need 3 normal vectors at each point of the triangle for your method?
    How comes that your “tnorm” has the same size as “t” (triangle indices) and not as the surface points “p”?

    Hope you have a tip.
    I’m really looking forward to testing your method with my data!!

    Cheers,
    María

    [Reply]

    UN:F [1.8.8_1072]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.8_1072]
    Rating: 0 (from 0 votes)
  7. María Herrojo Ruiz on Tue, 6th Apr 2010 21:15
  8. I got it.
    Now everything works fine.

    Great! Thanks for writing Inpolyedron. It is really fast!

    Cheers.
    María

    [Reply]

    UN:F [1.8.8_1072]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.8_1072]
    Rating: 0 (from 0 votes)
  9. Denis Lisin on Fri, 30th Jul 2010 16:44
  10. Thanks for the code, works fine.
    Important issue for me is it considers the points on boundary as inner points.

    [Reply]


    Luigi Giaccari Reply:

    Be careful with boundary points, numerical accuracy can be very painful!

    [Reply]

    UA:F [1.8.8_1072]
    Rating: 5.0/5 (1 vote cast)
    UA:F [1.8.8_1072]
    Rating: 0 (from 0 votes)
  11. Denis Lisin on Tue, 3rd Aug 2010 00:53
  12. Well, I implementing some combination of so-called meshless methods, so the pain with boundary points here isn’t so strong as usual. Actually i need your (great) function exclusively to visualize results.

    [Reply]

    UN:F [1.8.8_1072]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.8_1072]
    Rating: 0 (from 0 votes)
  13. Cam Straatsma on Sun, 15th Aug 2010 05:09
  14. Hi Luigi,

    I was just wondering how you generated the input data for the test geometries included with the function (i.e. the SphereSurface.mat, StubAxleSurface.mat, etc. files). Do you draw them in a CAD program and then use a triangular meshing algorithm?

    Thanks,

    Cam

    [Reply]


    Luigi Giaccari Reply:

    The input data can be retried from an stl file generated from whatever CAD system.

    To transalte it in matlab format you can use:

    http://www.advancedmcode.org/stl_import-import-function-for-stl-files.html

    [Reply]


    Cam Straatsma Reply:

    Great, thank you.

    [Reply]

    UN:F [1.8.8_1072]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.8_1072]
    Rating: 0 (from 0 votes)

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>