Пример #1
0
        v2x, v2y, v2z = s2_vertices[v2]
        v2 = Point3D(v2x, v2y, v2z)
        v3x, v3y, v3z = s2_vertices[v3]
        v3 = Point3D(v3x, v3y, v3z)
        vc = Point3D((v1x + v2x + v3x) / 3, (v1y + v2y + v3y) / 3,
                     (v1z + v2z + v3z) / 3)
        n_pi2 = v1.vector_to(v2).cross(
            v1.vector_to(v3)).normalise()  # normal vector of plane 2

        uv_distance = uc.distance_to(vc)
        d_u_from_v = -n_pi2.dot(uc.vector_to(vc))
        d_v_from_u = -n_pi1.dot(vc.vector_to(uc))

        try:
            result = triangle3d_intersects_triangle3d(u1x, u1y, u1z, u2x, u2y,
                                                      u2z, u3x, u3y, u3z, v1x,
                                                      v1y, v1z, v2x, v2y, v2z,
                                                      v3x, v3y, v3z)
        except NotImplementedError:
            continue

        if result[0]:

            ut1 = result[1]
            ut2 = result[2]

            s1_intersects[s1_tri_id] = True
            try:
                s1_intersections[s1_tri_id].append((s2_tri_id, ut1, ut2))
            except KeyError:
                s1_intersections[s1_tri_id] = [(s2_tri_id, ut1, ut2)]
# v1 = Point3D(0.6000000238418579, 1.600000023841858, 1.600000023841858)
# v2 = Point3D(0.6000000238418579, 0.6000000238418579, 1.600000023841858)
# v3 = Point3D(1.600000023841858, 0.6000000238418579, 1.600000023841858)

u1 = Point3D(0.2628655433654785, 0.4253253936767578, 0.0)
u2 = Point3D(0.21694427728652954, 0.4313342273235321, 0.12994596362113953)
u3 = Point3D(0.34689024090766907, 0.35102322697639465, 0.08031101524829865)

v1 = Point3D(0.30000001192092896, -0.5, 0.30000001192092896)
v2 = Point3D(0.30000001192092896, 0.5, -0.699999988079071)
v3 = Point3D(0.30000001192092896, 0.5, 0.30000001192092896)

t1 = Triangle(u1.x, u1.y, u1.z, u2.x, u2.y, u2.z, u3.x, u3.y, u3.z)
t2 = Triangle(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, v3.x, v3.y, v3.z)

result = triangle3d_intersects_triangle3d(t1, t2)

dx = np.array([u1.x, u2.x, u3.x])
dy = np.array([u1.y, u2.y, u3.y])
dz = np.array([u1.z, u2.z, u3.z])
t1_triangles = np.array([[0, 1, 2]])
mlab.triangular_mesh(dx, dy, dz, t1_triangles)

t1_cp = Point3D(dx.mean(), dy.mean(), dz.mean())
u1u2 = u1.vector_to(u2)
u1u3 = u1.vector_to(u3)
n_pi1 = u1u2.cross(u1u3).normalise()


dx = np.array([v1.x, v2.x, v3.x])
dy = np.array([v1.y, v2.y, v3.y])