View Full Version : Is point within object

01 January 2008, 05:15 PM
Anyone know of a script that will tell you if the point that you have selected is within another object (like a poly or something)... I remember seeing something that used a bounding box to detect this??

01 January 2008, 06:15 PM
check this out:

i think this is what you're looking for

01 January 2008, 09:28 PM
Depends on what exactly do you mean by point inside object. Usually it is defined that point can be inside a closed object only. In case that the object has holes the point is considered inside only if it lies on one of the triangles of the mesh.

There are some methods to do this but something is telling me it is not what you want to do.
You are basically trying to find a rough way of telling if the point is roughly inside an object, even if it contains holes.

You can start off by checking whether the point falls into the bounding box of the object. If not you can return false right away. Maybe in your case bounding box check will provide sufficient results and you could stop here.

Then you could use closestPointOnSurface to find the closest face to the point on the mesh. Then you could check whether the point is in front or on the back of the polygon according to its normal. So, if the point is behind the polygon (ie, the polygon looks away from the point) the point is likely to be inside (if the normals of the geometry are fine).
And if the point is in front of the polygon, it should be ouside of the model in most cases.

This might give you some kind of rough approximation for what you are looking for.

Hope it helps :)

01 January 2008, 01:52 AM
I have done this thing before. My steps:

1. Triangulate the mesh first.
2. Using Ray-Triangle intersection test for each triangle. if the hit number is odd, then it's inside the polygon. otherwise, it's outside.
3. If you have a dense mesh, use octree for acceleration.
My reason for triangulating first is because the the optimal code for ray-triangle intersection is abundant out there, so it's pretty fast.
I have the python script for step 1 and 2 only, since i need not do any acceleration (yet).
If you need it, i will post it here later.

01 January 2008, 05:52 AM
Thanks for all the replies... basically what I am trying to do is define areas of a scalp so that I can query follicles when a hairSys is created. I am scripting the modeling of hair, and part that means that I need to be able to define/call areas of follicles (ie. sideburns).

The scalp topology obviously changes quite a bit from model to model... at first I thought that I would place poly faces within sets... then use the sets to try and resolve which follicles ended up on the faces... but then I abandoned that to instead query the transformation values of the follicles (if the rot and trans are within a certain range)... but this has been unreliable.

... so I thought I would just go for the throat... and create shapes specifically to define areas of the scalp... then once the hair is generated, return the follicles that are spacially within the shapes... so the shapes could be whatever would work/perform best poly/nurbsSurf/lowRez/closed/no holes/ etc... and somewhat reusable model to model.

Any guidance or scripts are greatly welcomed.

05 May 2008, 11:45 AM
hey guys.

i've been tying to suss this one out myself. i ended up using closestPointOnMesh. My script needs to be tweaked for varying situations (different selection types) but the essentials are pretty much there. I posted it over here:

r4inm4ker, the intersection test sounds like the best way to do it with accurate results. Is octree something to do with API? Can you still post the python sript you mentioned?

rhythmone, not sure if that actually helps you at all. sorry if not.


CGTalk Moderation
05 May 2008, 11:45 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.