how much area colliding

hi everyone

my question:
i have 2 objects and this two shape starting collide, this 2 object not have rigidbody.
i want calculate how much nested this two object, like attached image:
82478-screen-shot-2016-11-19-at-231140.png

Sorry for the late response ^^. I currently have about 150 UnityAnswers tabs open.

Well as i said having arbitrary meshes makes it way more complicated. Especially since the right “red” object is not convex. If you only deal with convex objects it’s easier. So if you really need the general case there is one initial requirement: the meshes need to be closed otherwise the concept of “inside” and “outside” makes no sense. So if you have two arbitrary closed meshes you have to do;

  • split each mesh into one or multiple convex meshes. Every “closed” mesh can be broken down into convex meshes but it might not be that simple to do so. The result of the first step is that the initial Mesh A and Mesh B has been broken down into A1, A2, … and B1, B2, … where each one is a convex mesh.
  • In the second step you would convert each face of lets say all A meshes into mathematical planes that can be used to intersect the meshes with each other.
  • Now you have to cut down all B meshes by all planes of each A mesh. The resulting convex mesh is the intersection mesh between the two convex meshes. So when you intersect n x A meshes with m x B meshes you will end up with (n * m) x C meshes. However some of these meshes will be “empty” and can be discarded.
  • In the final step you have a collection of all intersection volumes as convex meshes. Now you just need to calculate the volume of those meshes. Since they are all convex you can simply split it logically into tetrahedron. From there it’s easy to calculate the volume of each part. Finally just add up the volume of each part.
  • If you want a “percentage” in relation to one of the two initial meshes you would need to calculate the volume of that reference mesh as well. Since you already have the mesh as convex parts that’s fairly easy.

If you have problems with the implementation, here’s my VisPortal demo. You can use the Polygon class inside PolyArea.cs to represent a single “face” / triangle of your mesh. It has a clipping method to clip it against some clipping planes. The great thing about convex meshes is that when you intersect all border planes with each other you get the exact faces of the mesh.

As i said this is not going to be easy. This is actually the same what is needed for calculating CSG operations on meshes.