Exemple #1
0
 def evaluate(self, x, y, z):
     v = Vector([x,y,z])
     dv1 = (v - self.v1).length
     dv2 = (v - self.v2).length
     if dv1 > dv2:
         distance_to_nearest = dv2
         nearest_vert = self.v2
         another_vert = self.v1
     else:
         distance_to_nearest = dv1
         nearest_vert = self.v1
         another_vert = self.v2
     edge = another_vert - nearest_vert
     to_nearest = v - nearest_vert
     if to_nearest.length == 0:
         return 0
     angle = edge.angle(to_nearest)
     if angle > pi/2:
         distance = distance_to_nearest
         vector = - to_nearest
     else:
         vector = LineEquation.from_two_points(self.v1, self.v2).projection_of_points(v)
         distance = vector.length
         vector = np.array(vector)
     if self.falloff is not None:
         return self.falloff(distance) * vector / distance
     else:
         return vector
Exemple #2
0
 def evaluate(self, x, y, z):
     v = Vector([x, y, z])
     dv1 = (v - self.v1).length
     dv2 = (v - self.v2).length
     if dv1 > dv2:
         distance_to_nearest = dv2
         nearest_vert = self.v2
         another_vert = self.v1
     else:
         distance_to_nearest = dv1
         nearest_vert = self.v1
         another_vert = self.v2
     edge = another_vert - nearest_vert
     to_nearest = v - nearest_vert
     if to_nearest.length == 0:
         return 0
     angle = edge.angle(to_nearest)
     if angle > pi / 2:
         distance = distance_to_nearest
     else:
         distance = LineEquation.from_two_points(
             self.v1, self.v2).distance_to_point(v)
     if self.falloff is not None:
         value = self.falloff(np.array([distance]))[0]
         return value
     else:
         return distance
Exemple #3
0
 def evaluate_grid(self, xs, ys, zs):
     n = len(xs)
     vs = np.stack((xs, ys, zs)).T
     v1 = np.array(self.v1)
     v2 = np.array(self.v2)    
     dv1s = np.linalg.norm(vs - v1, axis=1)
     dv2s = np.linalg.norm(vs - v2, axis=1)
     v1_is_nearest = (dv1s < dv2s)
     v2_is_nearest = np.logical_not(v1_is_nearest)
     nearest_verts = np.empty_like(vs)
     other_verts = np.empty_like(vs)
     nearest_verts[v1_is_nearest] = v1
     nearest_verts[v2_is_nearest] = v2
     other_verts[v1_is_nearest] = v2
     other_verts[v2_is_nearest] = v1
     
     to_nearest = vs - nearest_verts
     
     edges = other_verts - nearest_verts
     dot = (to_nearest * edges).sum(axis=1)
     at_edge = (dot > 0)
     at_vertex = np.logical_not(at_edge)
     at_v1 = np.logical_and(at_vertex, v1_is_nearest)
     at_v2 = np.logical_and(at_vertex, v2_is_nearest)
     
     distances = np.empty((n,))
     distances[at_edge] = LineEquation.from_two_points(self.v1, self.v2).distance_to_points(vs[at_edge])
     distances[at_v1] = dv1s[at_v1]
     distances[at_v2] = dv2s[at_v2]
     
     if self.falloff is not None:
         distances = self.falloff(distances)
         return distances
     else:
         return distances
Exemple #4
0
 def linear_search(segment):
     cpts = segment.get_control_points()
     start, end = cpts[0], cpts[-1]
     line = LineEquation.from_two_points(start, end)
     p = line.projection_of_point(src_point)
     t = locate_linear(start, end, p)
     if 0.0 <= t <= 1.0:
         u1, u2 = segment.get_u_bounds()
         u = (1 - t) * u1 + t * u2
         return u
     else:
         return None
Exemple #5
0
 def intersect_line(segment):
     cpts = segment.get_control_points()
     p1, p2 = cpts[0], cpts[-1]
     line = LineEquation.from_two_points(p1, p2)
     p = plane.intersect_with_line(line)
     p = np.array(p)
     u = locate_p(p1, p2, p)
     u1, u2 = segment.get_u_bounds()
     if u >= 0 and u <= 1.0:
         v = (1 - u) * u1 + u * u2
         return v, p
     else:
         return None
Exemple #6
0
    def evaluate_grid(self, xs, ys, zs):
        n = len(xs)
        vs = np.stack((xs, ys, zs)).T
        v1 = np.array(self.v1)
        v2 = np.array(self.v2)
        dv1s = np.linalg.norm(vs - v1, axis=1)
        dv2s = np.linalg.norm(vs - v2, axis=1)
        v1_is_nearest = (dv1s < dv2s)
        v2_is_nearest = np.logical_not(v1_is_nearest)
        nearest_verts = np.empty_like(vs)
        other_verts = np.empty_like(vs)
        nearest_verts[v1_is_nearest] = v1
        nearest_verts[v2_is_nearest] = v2
        other_verts[v1_is_nearest] = v2
        other_verts[v2_is_nearest] = v1

        to_nearest = vs - nearest_verts

        edges = other_verts - nearest_verts
        dot = (to_nearest * edges).sum(axis=1)
        at_edge = (dot > 0)
        at_vertex = np.logical_not(at_edge)
        at_v1 = np.logical_and(at_vertex, v1_is_nearest)
        at_v2 = np.logical_and(at_vertex, v2_is_nearest)

        line = LineEquation.from_two_points(self.v1, self.v2)

        vectors = np.empty((n, 3))
        vectors[at_edge] = line.projection_of_points(vs[at_edge]) - vs[at_edge]
        vectors[at_v1] = v1 - vs[at_v1]
        vectors[at_v2] = v2 - vs[at_v2]

        if self.falloff is not None:
            norms = np.linalg.norm(vectors, axis=1, keepdims=True)
            lens = self.falloff(norms)
            nonzero = (norms > 0)[:, 0]
            vectors[nonzero] = vectors[nonzero] / norms[nonzero][:, 0][
                np.newaxis].T
            R = (lens * vectors).T
            return R[0], R[1], R[2]
        else:
            R = vectors.T
            return R[0], R[1], R[2]
 def test_check_no(self):
     p1 = (1, 1, 1)
     p2 = (3, 3, 3)
     line = LineEquation.from_two_points(p1, p2)
     p3 = (5, 5, 6)
     self.assertFalse(line.check(p3))
 def test_from_two_points(self):
     p1 = (1, 1, 1)
     p2 = (3, 3, 3)
     line = LineEquation.from_two_points(p1, p2)
     self.assert_sverchok_data_equal(tuple(line.direction), (2, 2, 2))
     self.assert_sverchok_data_equal(tuple(line.point), p1)
Exemple #9
0
 def test_check_no(self):
     p1 = (1, 1, 1)
     p2 = (3, 3, 3)
     line = LineEquation.from_two_points(p1, p2)
     p3 = (5, 5, 6)
     self.assertFalse(line.check(p3))
Exemple #10
0
 def test_from_two_points(self):
     p1 = (1, 1, 1)
     p2 = (3, 3, 3)
     line = LineEquation.from_two_points(p1, p2)
     self.assert_sverchok_data_equal(tuple(line.direction), (2, 2, 2))
     self.assert_sverchok_data_equal(tuple(line.point), p1)