Results 1 to 6 of 6

Thread: How to identify if a point is inside a mesh

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2006
    Location
    Manila
    Posts
    7

    How to identify if a point is inside a mesh

    Hello, this is my second post here in the message boards. I have another problem that I'm really stuck on. I'm using c++.

    My question is, if given a point in 3d space, how am I going to identify if it is INSIDE, ON THE SURFACE, or OUTSIDE of my mesh. I represented my mesh by identifying it's vertices and its polygons with its faces. So thats where I'm stuck. My mesh is assumed to be enclosed and no hollow areas are available.

    Thanks.

  2. #2
    V-man
    Guest

    Re: How to identify if a point is inside a mesh

    For inside of a surface, you can look up barycentric coordinates.

    For inside or outside of a mesh, you can shoot a ray from the point to some random direction. If it crosses the mesh an odd number of times, it is inside, else outside. I have a lib that can tell you if an intersection occured. http://ee.1asphost.com/vmelkon/glhlibrary.html
    Search for the word "intersection" in the header file.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2006
    Location
    Manila
    Posts
    7

    Re: How to identify if a point is inside a mesh

    pseudocodes/codes are very much appreciated.
    Thanks.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Naarn, Austria
    Posts
    1,102

    Re: How to identify if a point is inside a mesh

    I assume P is the point you're interested in.

    R is a ray originating in P in some arbitrary direction (let's say (1,0,0)).

    Code :
    Ray R = Ray(P, Vector(1,0,0));
    int intersections = 0;
    foreach(Triangle T in your Mesh) {
        if(R intersects T)
            intersections++;
    }
    if(intersections % 2 == 1) {
        // INSIDE
    } else {
        // OUTSIDE
    }
    As for "exactly on the surface", you should code a special case in the ray-triangle intersection. If the intersection is only a short way from the beginning of the ray, you can count this as "on the surface", and abort the whole algorithm.

    It shouldn't be a problem to find some code for ray-triangle intersection with google, it's pretty common.

  5. #5
    Member Contributor
    Join Date
    Mar 2006
    Posts
    53

    Re: How to identify if a point is inside a mesh

    My question is, if given a point in 3d space, how am I going to identify if it is INSIDE, ON THE SURFACE, or OUTSIDE of my mesh.
    Just out of curiosity, what kind of mesh is this (e.g., is it closed, is it convex), and what do you need this test for?

  6. #6
    Junior Member Newbie
    Join Date
    Jul 2006
    Location
    Manila
    Posts
    7

    Re: How to identify if a point is inside a mesh

    It's closed, the mesh is imported from 3ds max. This test will be utilized for a wind flow application implemented in VC++ with openGL and glut.

Similar Threads

  1. Replies: 2
    Last Post: 11-20-2018, 02:20 AM
  2. How to know if point is inside a volume?
    By ei05tbe in forum OpenGL: General
    Replies: 3
    Last Post: 09-06-2010, 08:49 AM
  3. Point of intersection inside 3D triangle?
    By stargazer in forum OpenGL: General
    Replies: 1
    Last Post: 07-28-2005, 08:55 PM
  4. How do I identify the point beyond the object?
    By flytoopengl in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 03-31-2004, 01:07 PM
  5. point inside 6 planes
    By Bruno in forum OpenGL: Advanced Coding
    Replies: 21
    Last Post: 02-07-2001, 02:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean