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)
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))
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)))
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)))
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]
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))
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)))
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')
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()
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')
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))
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))
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))
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))
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))
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')
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()))
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')
def test_check(self): s1 = cm.plane(cm.ngon(1.0, 3)) self.assert_(s1.check())
def test_plane(self): w1 = cm.ngon(2.0, 5) f1 = cm.plane(w1) self.assert_(close(9.511, f1.area(), 0.001))
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))
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)))
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)
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)
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))
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)))
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)
def test_dump(self): s1 = cm.plane(cm.ngon(1.0, 3)) s1.dump() self.assert_(True)
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)
def tolerance(self): s1 = cm.plane(cm.ngon(1.0, 3)) self.assert_(close(s1.tolerance(), 1e-7, eps=1e-9))
def face_plane(): w1 = cm.ngon(2.0, 5) f1 = cm.plane(w1) save_top(f1, 'face_plane.png')
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))
def wire(self): w1 = cm.ngon(1.0, 3) s1 = cm.plane(w1) w2 = s1.wire() self.assert_(close(w1.length(), w2.length()))
def type(self): s1 = cm.plane(cm.ngon(1.0, 3)) self.assert_(s1.type() == 'plane')
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))