#Inside/Out
11 messages in this thread
Do any of you scripting or math maniacs have any suggestions on how to
determine if an x,y,z coordinate falls inside or outside of a mesh object? (All
suggestions welcome – regardless of how simple or complex.)
– Dave
>> inside or outside of a mesh object?
Answering my own question: How about determining if the point falls on the
side of EVERY nearest face that falls away from the normal? (Again,
suggestions are appreciated.)
Hi David,
I'm assuming that you're trying to determine whether a point's inside or
outside an arbritrary mesh. In other words, you aren't creating the mesh, just
checking your point(s) against an already present mesh.
I'd approach this problem in two parts;
Start with the mesh's bounding box. You can get this info from the object's
matrix and it's accessible from within a script or an IPAS routine. Once you
have the bound box, determine whether the point falls within its boundaries.
If the point is outside the bounding box, you can be sure that the point won't
fall inside your mesh. If it falls inside the bounding box, you then have to
determine whether it actually falls within the mesh object itself.
There are a couple of ways of determining that. I'd probably use a marching
cubes routine that subdivides the object's bounding box into smaller cubes and
then I'd test each cube for the presence of a face or vertex. If a face or
vertex falls within or intersects one of the cubes, mark that cube.
Once you've got all the cubes marked (or unmarked), you have a pretty good idea
of the surface of the mesh. Discard any cubes that are outside the marked
cubes, they represent a volume that's outside your mesh. What you're left with
is a bunch of cubes that intersect or are inside the surface of the mesh.
Now, test each of these remaining cubes for the presence of your point(s).
That's it. If the point is inside one of these cubes, it's probably inside the
mesh. I say probably because it all depends on the level of accuracy you're
using.
It's possible to get very accurate results by controlling the amount of
subdivision that you apply to the original bounding box to create your cubes.
The more cubes you create, the more accurate your representation of the mesh's
surface will be and the more accurate your determination of whether a point is
inside the mesh will be. Of course, this makes the scan slower and more memory
intensive too.
Using the initial bounding box test helps minimize the amount of work you have
to do by throwing out points that are obviously outside the mesh. This helps
speed thing up quite a bit.
I've written something similar in the past and it worked out great.
Hope this helps you out. Let me know if you need a hand or if you would like
more detail in the explanation.
Cya,
Danny…
>> bounding box… marching cubes… Let me know if you need a hand…
This gets me looking in the right direction. I'm faced with a few problems in
my script development:
1. I'm trying to dig through the cobwebs to the calculus, vector and matrix
mathematics I learned many years ago. (Time for that refresher class!)
2. I'm trying to catch up on many years of computer graphics technology – in
order to create some low-level scripting effects (implicit surfaces, mesh
transformations, spatial calculations and controlled-noise functions.)
3. I'm trying to avoid duplicating the years of research done by others, when
I'm sure there are well documented algorithms for most of what I'm trying to
do. (Of course, at $50+ each, these graphics books are getting expensive!)
4. Trying to squeeze in all this learning in the short time between when my
19-month old goes to sleep and I fall asleep on the computer. <g>
I will track down some info on the marching cubes procedure. If I find myself
completely lost in the math or algorithms, I may impose on you for some
guidance. This is an acedemic pursuit, for my own enlightenment and love of
graphics, so it is moving slowly and with no real urgency. Thank you very much
for your help.
– Dave
David:
It looks like Danny Mercurio has pretty much hit it on the head…
I'm curious: what's your application?
Martin
>> I'm curious: what's your application?
He he. In my (very limited) spare time, I'm still experimenting with various
TSE modules and the basic graphics principles. In this case, I'm trying to
fill a volume with evenly spaced objects.
In another experiment, I'm also tinkering with meshing an mathematically
defined surface.
(I'm feeling like Tim Brannan who in his message to you just said he felt like
"a monkey trying to comprehend quantum mechanics.")
Don't count on any results in the near future. I'm really going to require
some time and effort on these. I keep taking five steps back for each one
forward. (On the positive side, it's gotten me back into mathematics –
something I've ignored since college.)
– Dave
>> He he. In my (very limited) spare time, I'm still experimenting with
various TSE modules and the basic graphics principles. In this case, I'm
trying to fill a volume with evenly spaced objects. <<
I see. Such a procedure could be extremely useful, especially for roughing out
metaball objects from existing meshes! Hmmm… the possibilities…
>> In another experiment, I'm also tinkering with meshing an mathematically
defined surface. <<
Cough. Wheeeze.
>> (On the positive side, it's gotten me back into mathematics – something
I've ignored since college.) <<
Ain't it great!?
Martin
>> Hmmm… the possibilities… Cough. Wheeeze… Ain't it great!?
I'll let you know when I make it work. <Cough. Wheeeze. (g)>
Are you going to that visualization symposium whatchyamacallit in May? We'll
have to get together there.
– Dave
>> Are you going to that visualization symposium whatchyamacallit in May?
We'll have to get together there. <<
Yea, I'm actually giving a class (each day) on scripting. Otherwise, I'll
probably be seen loitering at the Schreiber booth, hawking my wares.
Martin
As Danny says, I would start out by testing against the object's bounding box.
If inside, I would then "draw" a theoretical ray from the point. Going along
that ray, count how many times that the ray passes through an object face. If
the number is even, you are outside the object. If even, you are inside.
For simplifying the testing of whether the ray passes through a face, I would
make the ray follow one of the axes. Should be rather simple <wg>.
LAM
ps: <wg> = wicked grin
>> Should be rather simple <wg>.
Yeah, and so is quantum physics! I like your suggestion though. As time
permits, I'll tinker with it. I'll post news of my success or failure here.
– Dave