4

I'm working on a Java project witch is really killing me. After several days of researching on different forums, looking for what I really need, I come to ask your help.

My data :

  • A .ply file (containing a 3D shape made of a lot of triangles)
  • A point (3D coordinates)

I would like to know if this point is contained inside the complex 3D shape.

I have split this problem in 2 smaller problems :

  • How can I represent the complex 3D shape in memory? (I found several libraries, but it seems really complex for the task I want to do : Java3D, JBullet, JME3...) I do not want my java application to show the object for now.

  • How can I know if this point is inside the 3D shape or not? (I thought to make a 3D vector starting from the point and to count the number of intersections with the shape, but I don't see how to do and witch library can I use?)

Maybe there are easier ways to do it, that's also why I come to you. I am really stuck now and I would like if this is possible without writing customs libraries...

(Sorry for my writing, I'm not English ^^)

Thanks for helping me.

Theodiablo
  • 41
  • 2
  • 1
    Like you suggested, you need to do ray triangle intersections and count them on one side of the point. So loading the object as an iterateable list of triangles sounds reasonable. Even though it's for 2D only you can use the [Point in Polygon Algorithm](http://alienryderflex.com/polygon/) as a reference. – Lucius Apr 03 '13 at 12:00

1 Answers1

0

Here is one approach. Not the best or the fastest, but once you have something working, it will be easier to improve upon.

How can I represent the complex 3D shape in memory?

Implement a quick and dirty PLY file format parser. Here is the PLY format spec. Load the data up and store it internally: an array for each X, Y, and Z. This is all just plain Java.

How can I know if this point is inside the 3D shape or not?

Define a line based on your point and some other arbitrary point. For each polygon, determine where it intersects the plane (some help) and if the intersection point is inside or outside the polygon (some help). As you suggested, then count the number of intersections to determine if the point is inside or outside your 3d shape.

martinez314
  • 12,162
  • 5
  • 36
  • 63
  • (I didn't know it would send my answer so fast ^^) I already made the PLY parser and I stocked every point/triangle in memory, but i don't know how to make it as a complete object in memory. The problem is that I have about 14000 triangles. I hope it won't boe too long. I will try to implement your solutions, thank you very much! – Theodiablo Apr 04 '13 at 18:05
  • 1
    14000 is not a lot of triangles. Anything over 2-10 million is a lot. Start simple. – joojaa Apr 08 '13 at 10:44