def closest_point_point_segment(a, b, c): ab = b - a; t = triangle.dot(c - a, ab) / triangle.dot(ab, ab) if (t < 0.0): t = 0.0 if (t > 1.0): t = 1.0 d = a + triangle.sxv(t, ab) return d
def get_dist_point_segment (a, b, c): ab = b - a ac = c - a bc = c - b e = triangle.dot(ac, ab) if (e <= 0.0): return triangle.dot(ac, ac) f = triangle.dot(ab, ab) if (e >= f): return triangle.dot(bc, bc) return math.sqrt(triangle.dot(ac, ac) - e * e / f)
def closest_point_outside(self, p): # si immagina di aver fatto' il check che il punto sia # fuori dal poliedro, al;trimqnti questo test potrebbe non funzionare closest_point = p best_sq_dist = float('inf') for p1, p2, p3 in self._triangles_points: q = triangle.closest_point_to_triangle(p, p1, p2, p2) sq_dist = triangle.dot(q - p, q - p) if (sq_dist < best_sq_dist): best_sq_dist = sq_dist closest_point = q return closest_point