mesh.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:meshpy 作者: BerkeleyAutomation 项目源码 文件源码
def tri_normals(self, align_to_hull=False):
        """Returns a list of the triangle normals.

        Parameters
        ----------
        align_to_hull : bool
            If true, we re-orient the normals to point outward from
            the mesh by using the convex hull.

        Returns
        -------
        :obj:`numpy.ndarray` of float
            A #triangles by 3 array of floats, where each 3-ndarray
            represents the 3D normal vector of the corresponding triangle.
        """
        # compute normals
        v0 = self.vertices_[self.triangles_[:,0],:]
        v1 = self.vertices_[self.triangles_[:,1],:]
        v2 = self.vertices_[self.triangles_[:,2],:]
        n = np.cross(v1 - v0, v2 - v0)
        normals = n / np.tile(np.linalg.norm(n, axis=1)[:,np.newaxis], [1,3])

        # reverse normal based on alignment with convex hull
        if align_to_hull:
            tri_centers = self.tri_centers()
            hull = ss.ConvexHull(tri_centers)
            hull_tris = hull.simplices
            hull_vertex_ind = hull_tris[0][0]
            hull_vertex = tri_centers[hull_vertex_ind]
            hull_vertex_normal = normals[hull_vertex_ind]
            v = hull_vertex.reshape([1,3])
            n = hull_vertex_normal
            ip = (tri_centers - np.tile(hull_vertex,
                  [tri_centers.shape[0], 1])).dot(n)
            if ip[0] > 0:
                normals = -normals
        return normals
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号