Beispiel #1
0
def trms_rotate():
    s1 = cm.box(1.0, 2.0, 3.0)
    s2 = cm.rotated(s1, (0.0, 0.0, 0.0), (0.0, 0.0, 1.0), math.pi / 2)
    v.viewstandard(viewtype='iso')
    v.display(s1, (1.0, 0.0, 0.0))
    v.display(s2, (0.0, 0.0, 1.0))
    v.fit()
    v.save('trms_rotate.png')
    v.clear()
def trms_rotate():
    s1 = cm.box(1.0, 2.0, 3.0)
    s2 = cm.rotated(s1, (0.0, 0.0, 0.0), (0.0, 0.0, 1.0), math.pi / 2)
    v.viewstandard(viewtype='iso')
    v.display(s1, (1.0, 0.0, 0.0))
    v.display(s2, (0.0, 0.0, 1.0))
    v.fit()
    v.save('trms_rotate.png')
    v.clear()
Beispiel #3
0
    def replicate(self, iface=0, iedge=0, angle=np.pi):
        """  replicate face iface along edge iedge

        Parameters
        ----------

        iface : int
            face index
        iedge : int
            edge index
        angle : float
            folding angle

        Notes
        -----
        add a node in the graph

        """
        self.nnode = self.nnode + 1
        # create a new face from face with index iface
        new_face = self.lfaces[iface].copy()
        # get the active edge of iface
        # points : edge termination
        # vedge : edge vector (non normalized)
        # axed : mirror axis orthogonal to vedge
        ed = self.lfaces[iface].subshapes('Edge')[iedge]
        points = ed.poly()
        vedge = np.array(points[1]) - np.array(points[0])
        axed = np.cross(vedge, np.array([0, 0, 1]))
        # mirror new face w.r.t axed
        new_face = cm.mirrored(new_face, ed.center(), axed)
        # modify normal orientation
        new_face = cm.rotated(new_face, new_face.center(), (1, 0, 0), np.pi)

        # append new face in PlanarNet.lfaces
        # update underlying graph
        # node position at centroid of the face

        self.lfaces.append(new_face)
        node_num = self.nnode - 1
        self.add_node(node_num,normal=new_face.normal())
        self.pos[node_num] = new_face.center()[0:2]
        self.add_edge(iface, node_num, angle=angle, iedge=iedge)
        self.shell = cm.Shell(self.lfaces)
Beispiel #4
0
 def test_rotated(self):
     s1 = cm.sphere(1.0)
     s2 = cm.rotated(s1, (1.0, 0.0, 0.0), (0.0, 0.0, 1.0), math.pi / 2)
     self.assert_(close(s2.center(), (1.0, -1.0, 0.0)))
Beispiel #5
0
 def test_rotated(self):
     s1 = cm.sphere(1.0)
     s2 = cm.rotated(s1, (1.0, 0.0, 0.0), (0.0, 0.0, 1.0), math.pi / 2)
     self.assert_(close(s2.center(), (1.0, -1.0, 0.0)))
Beispiel #6
0
    def fold(self, reverse=False):
        """ fold edges of the PlanarNet

        Returns
        -------

        A solid or a compound of faces

        Notes
        -----

        This method fold the planar net w.r.t to the edge angles.
        It yields a shell member

        """

        for edge in list(self.edges()):
            if0 = edge[0]
            if1 = edge[1]
            ag = self[if0][if1]['angle']
            # handle folding direction
            if reverse:
                angle = -ag
            else:
                angle = ag
            iedge = self[if0][if1]['iedge']

            ed = self.lfaces[if0].subshapes('Edge')[iedge]
            points = ed.poly()
            pdir = np.array(points[1]) - np.array(points[0])
            pabout = ed.center()

            # create 2 subgraphs
            self.remove_edge(if0, if1)
            #  DEPRECATED function in networkx
            lgraphs = list(nx.connected_component_subgraphs(nx.Graph(self)))
            #lgraphs = [ nx.Graph(self).subgraph(c).copy() for c in nx.connected_components(nx.Graph(self)) ] 

            ln0 = lgraphs[0].node.keys()
            ln1 = lgraphs[1].node.keys()
            self.add_edge(if0, if1, angle=ag, iedge=iedge)

            if if1 in ln1:
                lfaces1 = ln1
            else:
                lfaces1 = ln0

            # fold all faces in set lfaces1
            for f in lfaces1:
                self.lfaces[f] = cm.rotated(self.lfaces[f], pabout, pdir, angle)

        # update faces centroid in the Graph

        for iface in self.node:
            face = self.lfaces[iface]
            self.pos[iface] = face.center()[0:2]

        # creates the shell
        self.shell = cm.Shell(self.lfaces)
        if reverse:
            self.folded = False
        else:
            self.folded = True
            asolid = cm.Solid([self.shell])
            vertices = asolid.subshapes('Vertex')
            edges = asolid.subshapes('Edge')
            faces = asolid.subshapes('Face')

            Euler = len(vertices)-len(edges)+len(faces)

            print("V", len(vertices))
            print("E", len(edges))
            print("F", len(faces))
            print("Euler check (2): V-E+F :", Euler)

            if asolid.check():
                print("closed shape")
                # update the graph
            else:
                print("open shape")

            return asolid