def _calculate_normals(rr, tris):
 rr = rr.astype(np.float64)
 r1 = rr[tris[:, 0], :]
 r2 = rr[tris[:, 1], :]
 r3 = rr[tris[:, 2], :]
 tri_nn = _fast_cross_3d((r2 - r1), (r3 - r1))
 size = np.sqrt(np.sum((tri_nn * tri_nn), axis=1))
 size[(size == 0)] = 1.0
 tri_nn /= size[:, np.newaxis]
 npts = len(rr)
 nn = np.zeros((npts, 3))
 for verts in tris.T:
  for idx in range(3):
   nn[:, idx] += np.bincount(verts.astype(np.int32), tri_nn[:, idx], minlength=npts)
 size = np.sqrt(np.sum((nn * nn), axis=1))
 size[(size == 0)] = 1.0
 nn /= size[:, np.newaxis]
 return nn

def _calculate_normals ( rr , tris ) : rr = rr . astype ( np . float64 ) r1 = rr [ tris [ : , 0 ] , : ] r2 = rr [ tris [ : , 1 ] , : ] r3 = rr [ tris [ : , 2 ] , : ] tri_nn = _fast_cross_3d ( ( r2 - r1 ) , ( r3 - r1 ) ) size = np . sqrt ( np . sum ( ( tri_nn * tri_nn ) , axis = 1 ) ) size [ ( size == 0 ) ] = 1.0 tri_nn /= size [ : , np . newaxis ] npts = len ( rr ) nn = np . zeros ( ( npts , 3 ) ) for verts in tris . T : for idx in range ( 3 ) : nn [ : , idx ] += np . bincount ( verts . astype ( np . int32 ) , tri_nn [ : , idx ] , minlength = npts ) size = np . sqrt ( np . sum ( ( nn * nn ) , axis = 1 ) ) size [ ( size == 0 ) ] = 1.0 nn /= size [ : , np . newaxis ] return nn
efficiently compute vertex normals for triangulated surface .