Minimum distance segment function

Hello. I’m writing a modeling add-on, and I have the following mathematical problem.
2 edges in the space. Thay are not parallel and not incident. I know the coordinates of their vertices. How can I calculate the extreme vertices of the minimum distance segment between them?
I had started this function:

def trova_due_punti(vert1, vert2, vertA, vertB):  #vertex indexes
      c_vert1 = me.vertices[vert1].co  #put vertices coordinates in variables
      c_vert2 = me.vertices[vert2].co  
      c_vertA = me.vertices[vertA].co  
      c_vertB = me.vertices[vertB].co  

Now i don’t know how to proceed. Can somebody help me please? It’s important!

Thank you very much!

Attachments


Indices, not indexes

Comunque il segmento più corto che unisce 2 rette in uno spazio tridimensionale giace sulla retta perpendicolare ad entrambi i segmenti.
Quando due rette sono perpendicolari? Quando il loro prodotto scalare è uguale a zero.
Potrebbe capitare però che questa retta non intersechi mai il tuo segmento (poiché questa è una procedura per le rette, non per i segmenti). In ogni caso dovrebbe bastare prolungare idealmente il segmento, il vertice più vicino all’ipotetico punto di incontro è quello giusto.
In ogni caso internet è pieno di riferimenti a questo genere di problemi, cerca qualcosa su la distanza di 2 rette (quello che tu stai cercando è il segmento che giace sulla distanza delle 2 rette).

Search for perpendicular lines. There are many papers on this on the internet, search for distance between 2 lines, this is defined as the shortest path between the 2 edges