Differentiate with each coordinate of the other extreme, one at a time. Code: # A and B are two extremes # x1 <= x2, y1 <= y2, z1 <= z2 A = Vector3(x1, y1, z1) B = Vector3(x2, y2, z2) # Edges: From A to A->add(x2, 0, 0), From A to A->add(0, y2, 0), From A to A->add(0, 0, z2), From B->subtract(x1, 0, 0) to B, From B->subtract(0, y1, 0) to B, From B->subtract(0, 0, z1) to B