def project_points(points, tri_coords):
'''Using this to get the points off the surface
Takes the average length of two vecs off triangles
and applies it to the length of the normals.
This way the normal scales with the mesh and with
changes to the individual triangle vectors'''
t0 = tri_coords[:, 0]
t1 = tri_coords[:, 1]
t2 = tri_coords[:, 2]
tv1 = t1 - t0
tv2 = t2 - t0
cross = np.cross(tv1, tv2)
# get the average length of the two vectors and apply it to the cross product
sq = np.sqrt(np.einsum('ij,ij->i', cross, cross))
x1 = np.einsum('ij,ij->i', tv1, tv1)
x2 = np.einsum('ij,ij->i', tv2, tv2)
av_root = np.sqrt((x1 + x2) / 2)
cr_root = (cross / np.expand_dims(sq, axis=1)) * np.expand_dims(av_root, axis=1)
v1 = points - t0
v1_dots = np.einsum('ij,ij->i', cr_root, v1)
n_dots = np.einsum('ij,ij->i', cr_root, cr_root)
scale = np.nan_to_num(v1_dots / n_dots)
offset = cr_root * np.expand_dims(scale, axis=1)
drop = points - offset # The drop is used by the barycentric generator as points in the triangles
return drop, scale
评论列表
文章目录