Esempio n. 1
0
    def expand(self,iface,iedge,nedges,sign=1,angle=np.pi):
        """ expand face iface along edge iedge

        Parameters
        ----------

        iface : int
        iedge : int
        nedges : int
        angle : float

        """

        # add a new node to the graph
        self.nnode = self.nnode + 1
        # get the selected edge (iedge) of the selected face (iface)
        ed = self.lfaces[iface].subshapes('Edge')[iedge]

        # construct the equivalent complex number of the 2 extremities of the
        # edge
        points = ed.poly()
        z0 = points[0][0] + 1j*points[0][1]
        z1 = points[1][0] + 1j*points[1][1]
        # construct the new face with nedges sides
        lz = [z0, z1]
        for  k in range(nedges-2):
            dz = lz[-2]-lz[-1]
            lz.append(lz[-1]+ np.abs(dz)*np.exp(1j*(np.angle(dz)+sign*(nedges-2)*np.pi/nedges)))
        lpts = []
        for k in range(nedges):
            lpts.append((np.real(lz[k]),np.imag(lz[k]),0.0))
        lpts.append(lpts[0])
        new_face = cm.plane(cm.polygon(lpts))

        # control homogeneity of face normals
        if new_face.normal()[2]==-1:
            new_face = cm.plane(cm.polygon(lpts[::-1]))

        # append new face to list of faces
        self.lfaces.append(new_face)

        # new face number in the graph
        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)

        # construct Shell from Face
        self.shell = cm.Shell(self.lfaces)
Esempio n. 2
0
 def test_polygon(self):
     w1 = cm.polygon([(0.0, 0.0, 0.0),
                        (1.0, 0.0, 0.0),
                        (1.5, 1.0, 0.0),
                        (0.5, 1.5, 0.0),
                        (-0.5, -0.5, 0.0)])
     self.assert_(close(5.472, w1.length(), 0.001))
Esempio n. 3
0
 def test_polygon(self):
     w1 = cm.polygon([(0.0, 0.0, 0.0),
                      (1.0, 0.0, 0.0),
                      (1.5, 1.0, 0.0),
                      (0.5, 1.5, 0.0),
                      (-0.5, -0.5, 0.0)])
     self.assert_(close(5.472, w1.length(), 0.001))
Esempio n. 4
0
def wire_polygon():
    w1 = cm.polygon([(0.0, 0.0, 0.0),
                       (1.0, 0.0, 0.0),
                       (1.5, 1.0, 0.0),
                       (0.5, 1.5, 0.0),
                       (-0.5, -0.5, 0.0)])
    save_top(w1, 'wire_polygon.png', (0.0, 0.0, 0.0))
Esempio n. 5
0
    def __init__(self, **kwargs):
        """

        Parameters
        ----------
        pt : np.array (N x 2)
            points in the 0xy plane
        N : number of nodes of the first polygon
        l : edge length of the first polygon

        """
        self.folded = False
        pt = kwargs.pop('pt', [])
        N = kwargs.pop('N', 3)
        self.l = kwargs.pop('l', 1)
        if pt == []:
            al = (N - 2) * np.pi / (2 * N)
            self.r = np.sin(al) / np.sin(2 * np.pi / N)
            self.s = np.sqrt(self.r**2 - self.l**2/4.)
            t = np.linspace(0, N, N+1)
            u = 2 * np.pi * t / N
            pt = self.r * np.c_[np.cos(u), np.sin(u)]
        N = pt.shape[0]
        # conversion to 3D
        self.pt = np.c_[pt[:, 0], pt[:, 1], np.zeros(N)]
        w0 = cm.polygon(self.pt)
        face0 = cm.plane(w0)
        self.lfaces = [face0]
        self.nnode = 1
        nx.Graph.__init__(self)
        self.add_node(0,normal=face0.normal())
        self.add_node(0)
        self.pos = dict()
        self.pos[0] = face0.center()[0:2]
Esempio n. 6
0
def derived_revol():
    e1 = cm.arc(1.0, -math.pi / 2, math.pi / 2)
    e1.translate((3.0, 0.0, 0.0))
    w1 = cm.polygon([(3.0, 1.0, 0.0), (2.0, 1.0, 0.0), (2.0, -1.0, 0.0),
                     (3.0, -1.0, 0.0)])
    f1 = cm.plane(cm.wire([e1, w1]))
    f1.rotatex(math.pi / 2)
    s1 = cm.revol(f1, (0.0, 0.0, 0.0), (0.0, 0.0, 1.0), 2 * math.pi)
    save_iso(s1, 'derived_revol.png')
Esempio n. 7
0
def logging_face_fillet():
    w1 = cm.polygon([(-1.0, -1.0, 0.0),
                       (1.0, -1.0, 0.0),
                       (1.0, 1.0, 0.0),
                       (-1.0, 1.0, 0.0),
                       (-1.0, -1.0, 0.0)])
    f1 = cm.plane(w1)
    f1.fillet(0.25, f1.nearest('vertex', [(1.0, 1.0, 0.0), (-1.0, -1.0, 0.0)]))
    save_top(f1, 'logging_face_fillet.png')
Esempio n. 8
0
def derived_revol():
    e1 = cm.arc(1.0, -math.pi / 2, math.pi / 2)
    e1.translate((3.0, 0.0, 0.0))
    w1 = cm.polygon([(3.0, 1.0, 0.0),
                       (2.0, 1.0, 0.0),
                       (2.0, -1.0, 0.0),
                       (3.0, -1.0, 0.0)])
    f1 = cm.plane(cm.wire([e1, w1]))
    f1.rotatex(math.pi / 2)
    s1 = cm.revol(f1, (0.0, 0.0, 0.0), (0.0, 0.0, 1.0), 2 * math.pi)
    save_iso(s1, 'derived_revol.png')
Esempio n. 9
0
def logging_face_fillet():
    w1 = cm.polygon([(-1.0, -1.0, 0.0), (1.0, -1.0, 0.0), (1.0, 1.0, 0.0),
                     (-1.0, 1.0, 0.0), (-1.0, -1.0, 0.0)])
    f1 = cm.plane(w1)
    f1.fillet(0.25, f1.nearest('vertex', [(1.0, 1.0, 0.0), (-1.0, -1.0, 0.0)]))
    save_top(f1, 'logging_face_fillet.png')
Esempio n. 10
0
def wire_polygon():
    w1 = cm.polygon([(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (1.5, 1.0, 0.0),
                     (0.5, 1.5, 0.0), (-0.5, -0.5, 0.0)])
    save_top(w1, 'wire_polygon.png', (0.0, 0.0, 0.0))