title: Can't implement GJK distance algorithm
body: <p>I'm trying to design my own physics engine from scratch, as well as the vector/matrix libraries.
  Everything worked beautifully so far, until I tried to implement collision detection in my library. First with SAT, worked great for detecting, but I wanted to find the distance between the objects as well. Then I tried to implement the GJK distance algorithm, just to see if I can find the distance between the origin and a polygon. But it just doesn't work, the smallest distance perceived by the algorithm that I implemented was one of the vertex of the polygon:</p>
  
  <p><a href="https://postimg.org/image/c8r4pnkk7/" rel="nofollow noreferrer"><img src="https://s15.postimg.org/e0k3kk3x7/stack1.png" alt="stack1.png"></a></p>
  
  <p>I know I made the other libraries from scratch, but I'm positive that they are working. Anyways, here's the code where I've implemented the GJK:</p>
  
  <pre><code>    #objectL[0] is a hexagon
      v = objectL[0].nodes[0]
      W = []
      u = 0
      close_enough = False
      while not close_enough and v != Vector(0,0): 
          w = objectL[0].support(-v)  
          d = v*w/abs(v)  #*:dot product abs:magnitude
          u = max(u,d)
          close_enough = abs(v) - u &lt;= 0.0001
          if not close_enough:
              W.append(w)
              while len(W)&gt;2:
                  del W[0]
              v = Vector(0,0).vectorToLine(*W) #distance from the origin to the simplex
                                               #formed by W
  </code></pre>
  
  <p>And now the support method:</p>
  
  <pre><code>    def support(self,axis):
      maxP = self.nodes[0]*axis  #dot product of first vertex with the axis
      n = self.nodes[0]
      for node in self.nodes[1:]:
          p = node*axis
          if p&gt;maxP:
              maxP = p
              n = node
      return node
  </code></pre>
  
  <p>Those are the code snippets, that I think is where the error is, but I can't find it. The GJK algorithm I've copied from <a href="http://www.dtecta.com/papers/jgt98convex.pdf" rel="nofollow noreferrer">here</a>. Thanks!</p>
  
  <p>Edit:
  <a href="http://www.filedropper.com/physics_2" rel="nofollow noreferrer">Here</a> is my project(implemented in pygame)</p>