Posted by
philjord on
Aug 13, 2017; 9:52pm
URL: https://forum.jogamp.org/Intersection-of-two-triangles-tp4038124p4038125.html
Hi,
I'm not sure how far you've investigated so far, nor what your end goal is exactly so I'll give you some pointers and we can go from there.
Firstly, as far as I'm aware intersection points are all you an get out of Java3D collision, and in fact most (all?) physics colliders. I don't recall anything handing a line equation back as a result ( presumably in some sort of z = mx+ny + c style vector3f).
The most common way to get collision/intersections in Java3D is by using Behaviors, that report when things are colliding, like this
https://www.java-tips.org/other-api-tips-100035/119-java3d/2242-collision-detection-with-java3d.htmlor
http://www.java2s.com/Code/Java/3D/TickTockCollision.htmBut this is probably not what you want as it just reports nodes that collide.
However the Picking API does a more useful job.
The com.sun.j3d.utils.pickfast.PickTool from j3dutils project will return PickResult out of any scene branch for a given ray, cone, cylinder or segment, but NOT shape.
So although this is a start it probably isn't what you need without extension.
It does show how the BranchGroups have utility methods for picking that end up using the PickInfo methods for picking and eventually arrive at the various intersect* methods of GeometryArrayRetained which is exactly the sort of intersection code you want.
However because you can't add new PickShapes the only way to use this for geometry/geometry would be to build a bounding polytope shape from one of your geometries.
So if you are examining a single geometry versus the rest of your scene graph this is probably a fine way to do it. If you want a general purpose all geometries against each other, you'd need to use the collision behaviors then for each wake up do a more detailed PickResult via a bounding polytope for one of them.
Note for any of the above you need to set the java3d picking system to use GEOMETRY not BOUNDS and set the various capabilities on each Node, which is easiest to do using the J3dUtils PickTool.setCapabilities() method.
Finally, in my code I mainly want mouse picking from the Canvas3D so I use the com.sun.j3d.utils.pickfast package which does the job very well.
For general physics-like work I use the excellent JBullet
http://jbullet.advel.cz/ which is really very good, but might be a large hammer if all you want is intersection data.
Hope this gives you some pointers, please have a look at the various areas I mentioned then get back to us with more detail on what you need done.