# Moving vertices of two objects away from each other

Consider having two (multiple) objects that are very close to each other. Is there any algorithm which can identify vertices of these objects that their distances are less than a tolerance and then move those vertices away from each other until the defined tolerance is reached? the figure is a 2D representation of the problem which is actually in 3d space.

• Gonna need more information on this. How many vertices are you talking about? Can you create a diagram image to show what you mean? – bertmoog Sep 15 '17 at 18:06
• please look at the updated image – Benancio Sep 15 '17 at 18:23
• Yes, I understand the tolerance factor, but I'm assuming you don't mean two one-vertex-objects. How many vertices are you talking about? All of the vertices of an object? Do you want the object to stay intact (i.e. keep it's form... be static)? Are you applying physics/rigid-body to the objects? Animating them? – bertmoog Sep 15 '17 at 18:57
• There are potentially multiple ways of doing this, you just need to narrow down the application. – bertmoog Sep 15 '17 at 19:16
• objects are static, each object has a few hundred vertices, a proximity query for each vertex of one objects with all vertices of surrendering objects can identify the vertices that are "close" to each other, then those pairs need to be distanced. however, they should not be distance too much since it is desired to keep the shape and volume of the objects intact. – Benancio Sep 15 '17 at 19:55

Probably a nice balance between easy to implement and reasonably efficient would be to create a BVHTree for the mesh of one object, and query that with all the vertices of the other mesh using find_nearest_range(...).
Moving the vertices away is probably easiest if you mark the entire mesh as smooth first. That will casue the vertex normals to be in the opposite direction you want to move the vertices in. Then, for each vertex v that you want to move, you can do v.co -= f * v.normal, where f is a smoothing factor. The value of f depends on how quickly you want the vertices to move. You can use a fixed value like 0.01 to move them by 1/100th unit, or you could use a dynamic value that depends on the distance between the two meshes at that point.