Ejemplo 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)
Ejemplo n.º 2
0
 def test_to_step(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     r1 = s1.area()
     s1.to_step('tmp.stp')
     s2 = cm.from_step('tmp.stp')
     r2 = s2.area()
     self.assert_(close(r1, r2))
Ejemplo n.º 3
0
 def test_subcenters(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     cs = s1.subcenters('Vertex')
     rt3d2 = math.sqrt(3.0) / 2
     self.assert_(close(cs[0], (-0.5, rt3d2, 0.0)) and
                  close(cs[1], (-0.5, -rt3d2, 0.0)) and
                  close(cs[2], (1.0, 0.0, 0.0)))
Ejemplo n.º 4
0
 def test_subcenters(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     cs = s1.subcenters('vertex')
     rt3d2 = math.sqrt(3.0) / 2
     self.assert_(close(cs[0], (-0.5, rt3d2, 0.0)) and
                  close(cs[1], (-0.5, -rt3d2, 0.0)) and
                  close(cs[2], (1.0, 0.0, 0.0)))
Ejemplo 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]
Ejemplo n.º 6
0
 def test_to_iges(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     r1 = s1.area()
     s1.to_iges('tmp.igs', brep_mode=1)
     s2 = cm.from_iges('tmp.igs')
     r2 = s2.area()
     self.assert_(close(r1, r2))
Ejemplo n.º 7
0
 def test_to_step(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     r1 = s1.area()
     s1.to_step('tmp.stp')
     s2 = cm.from_step('tmp.stp')
     r2 = s2.area()
     self.assert_(close(r1, r2))
Ejemplo n.º 8
0
 def test_copy(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     s2 = s1.copy()
     s1.translate((1.0, 1.0, 1.0))
     self.assert_(
         close(s2.center(), (0.0, 0.0, 0.0))
         and close(s1.center(), (1.0, 1.0, 1.0)))
Ejemplo n.º 9
0
 def test_to_iges(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     r1 = s1.area()
     s1.to_iges('tmp.igs', brep_mode=1)
     s2 = cm.from_iges('tmp.igs')
     r2 = s2.area()
     self.assert_(close(r1, r2))
Ejemplo n.º 10
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')
Ejemplo n.º 11
0
def derived_offset_face():
    w1 = cm.ngon(8.0, 6)
    f1 = cm.offset(cm.plane(w1), 1.0)[0]
    v.viewstandard(viewtype='top')
    v.display(w1, (0.0, 0.0, 0.0))
    v.display(f1)
    v.fit()
    v.save('derived_offset_face.png')
    v.clear()
Ejemplo n.º 12
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')
Ejemplo n.º 13
0
def derived_offset_face():
    w1 = cm.ngon(8.0, 6)
    f1 = cm.offset(cm.plane(w1), 1.0)[0]
    v.viewstandard(viewtype='top')
    v.display(w1, (0.0, 0.0, 0.0))
    v.display(f1)
    v.fit()
    v.save('derived_offset_face.png')
    v.clear()
Ejemplo n.º 14
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')
Ejemplo n.º 15
0
    def test_offset(self):
        w1 = cm.ngon(8.0, 6)
        f1 = cm.offset(cm.plane(w1), 1.0)[0]

        b1 = cm.box(10.0, 10.0, 10.0)
        b1.translate((-5.0, -5.0, 0.0))
        c1 = cm.cylinder(2.5, 20.0)
        c1.translate((0.0, 0.0, -5.0))
        s1 = b1 - c1
        s2 = cm.offset(s1, 1.0)[0]

        # empirical
        self.assert_(close(217.418, f1.area(), 0.001) and
                     close(1608.966, s2.volume(), 0.001))
Ejemplo n.º 16
0
    def test_offset(self):
        w1 = cm.ngon(8.0, 6)
        f1 = cm.offset(cm.plane(w1), 1.0)[0]

        b1 = cm.box(10.0, 10.0, 10.0)
        b1.translate((-5.0, -5.0, 0.0))
        c1 = cm.cylinder(2.5, 20.0)
        c1.translate((0.0, 0.0, -5.0))
        s1 = b1 - c1
        s2 = cm.offset(s1, 1.0)[0]

        # empirical
        self.assert_(
            close(217.418, f1.area(), 0.001)
            and close(1608.966, s2.volume(), 0.001))
Ejemplo n.º 17
0
    def test_offset(self):
        w1 = cm.ngon(8.0, 6)
        f1 = cm.offset(cm.plane(w1), 1.0)[0]

        b1 = cm.box(10.0, 10.0, 10.0)
        b1.translate((-5.0, -5.0, 0.0))
        c1 = cm.cylinder(2.5, 20.0)
        c1.translate((0.0, 0.0, -5.0))
        s1 = b1 - c1
        # print("s1 is : %s" % s1)
        assert isinstance(s1, cm.Solid)
        s2 = cm.offset(s1, 1.0)
        # print("s2 is : %s" % s2)
        s2 = s2[0]

        # empirical
        self.assert_(close(217.418, f1.area(), 0.001) and
                     close(1608.966, s2.volume(), 0.001))
Ejemplo n.º 18
0
    def test_fillet(self):
        s = cm.plane(cm.ngon(1.0, 3))
        s1 = s.copy()
        s1.fillet(0.2)
        r1 = s1.area()

        s1 = s.copy()
        s1.fillet(0.2, [0])
        r2 = s1.area()

        s1 = s.copy()
        s1.fillet(0.2, [(1.0, 0.0, 0.0)])
        r3 = s1.area()

        s1 = s.copy()
        s1.fillet([(0.1, [0]), (0.2, [1]), (0.3, [2])])
        r4 = s1.area()
        # empirical
        self.assert_(
            close(r1, 1.217, eps=0.001) and close(r2, 1.272, eps=0.001)
            and close(r3, 1.272, eps=0.001) and close(r4, 1.203, eps=0.001))
Ejemplo n.º 19
0
    def test_fillet(self):
        s = cm.plane(cm.ngon(1.0, 3))
        s1 = s.copy()
        s1.fillet(0.2)
        r1 = s1.area()

        s1 = s.copy()
        s1.fillet(0.2, [0])
        r2 = s1.area()

        s1 = s.copy()
        s1.fillet(0.2, [(1.0, 0.0, 0.0)])
        r3 = s1.area()

        s1 = s.copy()
        s1.fillet([(0.1, [0]),
                   (0.2, [1]),
                   (0.3, [2])])
        r4 = s1.area()
        # empirical
        self.assert_(close(r1, 1.217, eps=0.001) and
                     close(r2, 1.272, eps=0.001) and
                     close(r3, 1.272, eps=0.001) and
                     close(r4, 1.203, eps=0.001))
Ejemplo n.º 20
0
def face_face_from():
    w1 = cm.ngon(2.0, 8)
    w2 = cm.ngon(10.0, 4)
    f2 = cm.plane(w1)
    f1 = cm.face_from(f2, w2)
    save_top(f1, 'face_face_from.png')
Ejemplo n.º 21
0
 def test_surface(self):
     w1 = cm.ngon(2.0, 8)
     w2 = cm.ngon(10.0, 4)
     f2 = cm.plane(w1)
     f1 = cm.face_from(f2, w2)
     self.assert_(close(200.0, f1.area()))
Ejemplo n.º 22
0
def derived_prism():
    f1 = cm.plane(cm.ngon(2.0, 6))
    s1 = cm.prism(f1, (0.0, 0.0, 1.0))
    save_iso(s1, 'derived_prism.png')
Ejemplo n.º 23
0
 def test_check(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     self.assert_(s1.check())
Ejemplo n.º 24
0
 def test_plane(self):
     w1 = cm.ngon(2.0, 5)
     f1 = cm.plane(w1)
     self.assert_(close(9.511, f1.area(), 0.001))
Ejemplo n.º 25
0
 def test_bounds(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     rt3d2 = math.sqrt(3.0) / 2
     print('bounds', s1.bounds())
     self.assert_(
         close(s1.bounds(), (-0.5, -rt3d2, 0.0, 1.0, rt3d2, 0.0), eps=0.1))
Ejemplo n.º 26
0
 def test_fix(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     s1.translate((1.0, 2.0, 3.0))
     s1.fix()
     self.assert_(close(s1.center(), (1.0, 2.0, 3.0)))
Ejemplo n.º 27
0
 def test_nearest(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     i1 = s1.nearest('Vertex', [(1.0, 0.0, 0.0)])[0]
     self.assert_(i1 == 2)
Ejemplo n.º 28
0
 def test_subshapes(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     ws = s1.subshapes('wire')
     es = s1.subshapes('edge')
     vs = s1.subshapes('vertex')
     self.assert_(len(vs) == 3 and len(es) == 3 and len(ws) == 1)
Ejemplo n.º 29
0
 def test_subtolerance(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     subtols = s1.subtolerance()
     self.assert_(close(subtols, (1e-7, 1e-7, 1e-7), eps=1e-9))
Ejemplo n.º 30
0
 def test_copy(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     s2 = s1.copy()
     s1.translate((1.0, 1.0, 1.0))
     self.assert_(close(s2.center(), (0.0, 0.0, 0.0)) and
                  close(s1.center(), (1.0, 1.0, 1.0)))
Ejemplo n.º 31
0
 def test_nearest(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     i1 = s1.nearest('vertex', [(1.0, 0.0, 0.0)])[0]
     self.assert_(i1 == 2)
Ejemplo n.º 32
0
 def test_dump(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     s1.dump()
     self.assert_(True)
Ejemplo n.º 33
0
 def test_fix(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     s1.translate((1.0, 2.0, 3.0))
     s1.fix()
     self.assert_(close(s1.center(), (1.0, 2.0, 3.0)))
Ejemplo n.º 34
0
 def test_subshapes(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     ws = s1.subshapes('Wire')
     es = s1.subshapes('Edge')
     vs = s1.subshapes('Vertex')
     self.assert_(len(vs) == 3 and len(es) == 3 and len(ws) == 1)
Ejemplo n.º 35
0
 def tolerance(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     self.assert_(close(s1.tolerance(), 1e-7, eps=1e-9))
Ejemplo n.º 36
0
def face_plane():
    w1 = cm.ngon(2.0, 5)
    f1 = cm.plane(w1)
    save_top(f1, 'face_plane.png')
Ejemplo n.º 37
0
def face_plane():
    w1 = cm.ngon(2.0, 5)
    f1 = cm.plane(w1)
    save_top(f1, 'face_plane.png')
Ejemplo n.º 38
0
 def test_check(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     self.assert_(s1.check())
Ejemplo n.º 39
0
def derived_prism():
    f1 = cm.plane(cm.ngon(2.0, 6))
    s1 = cm.prism(f1, (0.0, 0.0, 1.0))
    save_iso(s1, 'derived_prism.png')
Ejemplo n.º 40
0
 def test_dump(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     s1.dump()
     self.assert_(True)
Ejemplo n.º 41
0
 def test_bounds(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     rt3d2 = math.sqrt(3.0) / 2
     print('bounds', s1.bounds())
     self.assert_(close(s1.bounds(),
                        (-0.5, -rt3d2, 0.0, 1.0, rt3d2, 0.0), eps=0.1))
Ejemplo n.º 42
0
 def test_subtolerance(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     subtols = s1.subtolerance()
     self.assert_(close(subtols, (1e-7, 1e-7, 1e-7), eps=1e-9))
Ejemplo n.º 43
0
 def tolerance(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     self.assert_(close(s1.tolerance(), 1e-7, eps=1e-9))
Ejemplo n.º 44
0
 def wire(self):
     w1 = cm.ngon(1.0, 3)
     s1 = cm.plane(w1)
     w2 = s1.wire()
     self.assert_(close(w1.length(), w2.length()))
Ejemplo n.º 45
0
 def type(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     self.assert_(s1.type() == 'plane')
Ejemplo n.º 46
0
 def type(self):
     s1 = cm.plane(cm.ngon(1.0, 3))
     self.assert_(s1.type() == 'plane')
Ejemplo n.º 47
0
 def test_plane(self):
     w1 = cm.ngon(2.0, 5)
     f1 = cm.plane(w1)
     self.assert_(close(9.511, f1.area(), 0.001))
Ejemplo n.º 48
0
def face_face_from():
    w1 = cm.ngon(2.0, 8)
    w2 = cm.ngon(10.0, 4)
    f2 = cm.plane(w1)
    f1 = cm.face_from(f2, w2)
    save_top(f1, 'face_face_from.png')
Ejemplo n.º 49
0
 def test_surface(self):
     w1 = cm.ngon(2.0, 8)
     w2 = cm.ngon(10.0, 4)
     f2 = cm.plane(w1)
     f1 = cm.face_from(f2, w2)
     self.assert_(close(200.0, f1.area()))
Ejemplo n.º 50
0
 def test_prism(self):
     f1 = cm.plane(cm.ngon(2.0, 6))
     s1 = cm.prism(f1, (0.0, 0.0, 1.0))
     # empirical
     self.assert_(close(10.392, s1.volume(), 0.001))
Ejemplo n.º 51
0
 def test_prism(self):
     f1 = cm.plane(cm.ngon(2.0, 6))
     s1 = cm.prism(f1, (0.0, 0.0, 1.0))
     # empirical
     self.assert_(close(10.392, s1.volume(), 0.001))
Ejemplo n.º 52
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')
Ejemplo n.º 53
0
 def wire(self):
     w1 = cm.ngon(1.0, 3)
     s1 = cm.plane(w1)
     w2 = s1.wire()
     self.assert_(close(w1.length(), w2.length()))