How to get common part of two meshes?

I am working on cutting meshes. What am I exactly trying to achieve is that:

Input - two meshes(procedurally generated of course)

Output - three meshes(or more, depends on the given meshes)

A - which is a meshA substract mesh B,

B - which is a common part of meshes A and B,

C - which is a mesh B substract mesh A.

I am using the Triangulator that for the given set of vertices creates triangles for me. All I have to do is to give him those vertices, and here goes the question. Is there any algorithm that would help me to do this? Maybe your brilliant idea that came into your mind at the time you saw this picture?

2280526--153114--1stack.png

You are describing a boolean operand . Look into the term boolean. That may lead you to some solutions you seek.