def __init__(self, bbox, **kargs): F = simple.cuboid(*bbox) Actor.__init__(self, F, mode='wireframe', lighting=False, opak=True, **kargs)
def run(): clear() transparent() smoothwire nsphere = 10 S = sphere(nsphere) bbs = cuboid(*S.bbox()).toMesh().scale([0.8, 0.8, 1]).rot(30, 1).rot( 20, 0).shear(2, 1, 0.3).toSurface() clippedIn = vtkClip(S, implicitdata=bbs, method='surface', insideout=0) clippedOut = vtkClip(S, implicitdata=bbs, method='surface', insideout=1) draw(clippedIn, color=red, alpha=1) draw(clippedOut, color=blue, alpha=1) draw(bbs, color=yellow)
def run(): clear() smooth() image = os.path.join(pf.cfg['pyformexdir'], 'data', 'butterfly.png') F = simple.cuboid().centered().toMesh() G = Formex('4:0123') H = G.replic2(3, 2).toMesh().setProp(arange(1, 7)).centered() K = G.scale(200).toMesh() K.attrib(color=yellow, rendertype=2, texture=image) draw([F, H, K], texture=image) drawText(image, (200, 20), size=20) view('iso') zoomAll() zoom(0.5) bgcolor(color=[white, yellow, yellow, white], image=image)
def run(): smoothwire() print("======================") print("A cube with side = 1.0") F = cuboid().toMesh().convert('tet4').toFormex() clear() draw(F.toMesh().getBorderMesh()) print("Number of tetrahedrons: %s" % F.shape[0]) print("Bounding box: %s" % F.bbox()) V, M, C, I = inertia.tetrahedral_inertia(F.coords) # Analytical Va = 1. Ma = Va Ca = [0.5, 0.5, 0.5] Ia = [1. / 6, 1. / 6, 1. / 6, 0., 0., 0.] print("Volume = %s (corr. %s)" % (V, Va)) print("Mass = %s (corr. %s)" % (M, Ma)) print("Center of mass = %s (corr. %s)" % (C, Ca)) print("Inertia tensor = %s (corr. %s)" % (I, Ia)) pause() print("======================") print("A sphere with radius = 1.0") # Increase the quality to better approximate the sphere quality = 4 F = sphere(quality).tetgen().toFormex() clear() draw(F.toMesh().getBorderMesh()) print("Number of tetrahedrons: %s" % F.shape[0]) print("Bounding box: %s" % F.bbox()) V, M, C, I = inertia.tetrahedral_inertia(F.coords) # Analytical Va = 4 * pi / 3 Ma = Va Ca = [0., 0., 0.] ia = 8 * pi / 15 Ia = [ia, ia, ia, 0., 0., 0.] print("Volume = %s (corr. %s)" % (V, Va)) print("Mass = %s (corr. %s)" % (M, Ma)) print("Center of mass = %s (corr. %s)" % (C, Ca)) print("Inertia tensor = %s (corr. %s)" % (I, Ia))
def testConverts(): """_This debug function generates a .neu file for each element type""" chdir('~') testdir = 'f2fluTests' if not os.path.exists(testdir): os.makedirs(testdir) chdir(testdir) from pyformex.simple import cuboid mesh = Formex([0., 0., 0.]).extrude(3, dir=0).toMesh().extrude(3, dir=1) write_neu('test-quad4.neu', mesh) write_neu('test-tri3.neu', mesh.convert('tri3')) mesh = cuboid().toMesh().convert('hex8-8') write_neu('test-hex8.neu', mesh) mesh = Mesh([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.], [1., 0., 1.], [0., 1., 1.]], [[0, 1, 2, 3, 4, 5]]) write_neu('test-wed6.neu', mesh) mesh = Mesh([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], [[0, 1, 2, 3]], eltype='tet4') write_neu('test-tet4.neu', mesh)
def run(): global line, H, C, CS, savewait savewait = delay(0.5) clear() lights(True) view('iso') smooth() transparent(state=False) linewidth(2) setDrawOptions({'bbox':None}) # read the model of the horse F = Formex.read(getcfg('datadir')+'/horse.pgf') # make sure it is centered F = F.centered() # scale it to unity size and head it in the x-direction xmin, xmax = F.bbox() H = F.scale(1./(xmax[0]-xmin[0])).rotate(180, 1) # create the global coordinate system CS0 = CS = CoordSys() # some text # A storage for the scenes script = [] # Scene 0: The story starts idyllic T = 'There once was a white horse running free in the forest.' script += [ createScene(text=T, caged=False, color=7) ] sleep(3) # Scene 1: Things turn out badly T = 'Some wicked pyFormex user caged the horse and transported it around.' # apply same transformations on model and coordinate system H, CS = [ i.translate([0., 3., 6.]) for i in [H, CS] ] C = simple.cuboid(*H.bbox()) script += [ createScene(text=T) ] sleep(2) # Scene 2..n: caged movements T = 'The angry horse randomly changed colour at each step.' script += [ createScene(text=T, move=1) ] m = len(script) n = 16 script += [ createScene(move=i) for i in range(m, n, 1) ] sleep(2) # Scene n+1: the escape T = 'Finally the horse managed to escape from the cage.\nIt wanted to go back home and turned black,\nso it would not be seen in the night.' escape = script[-1] script += [ createScene(text=T, color=0, caged=False) ] undraw(escape) sleep(3) # The problem T = "But alas, it couldn't remember how it got there!!!" drawText(T, (20, line), size=20) line += line_inc for s in script[:-2]: sleep(0.1) undraw(s) sleep(3) # The solution T = "But thanks to pyFormex's orientation,\nit could go back in a single step,\nstraight through the bushes." drawText(T, (20, line), size=20) line += 3*line_inc H = H.transformCS(CS0, CS) draw(Formex([[CS.points()[3], CS0.points()[3]]])) sleep(3) T = "And the horse lived happily ever after." script += [ createScene(text=T, color=7, caged=False) ] undraw(script[-2])
def hex_mesh_huge(): nx, ny, nz = 20, 20, 8 F = simple.cuboid().replic2(nx, ny).replic(nz, 1., 2) F += F.trl([nx, ny, nz]) return F.toMesh()
def hex_mesh_orig(): x, y, z = 10, 10, 8 F = simple.cuboid().replic2(x, x).replic(z, 1., 2) F += F.trl([x, y, z]) return F.toMesh()
def hex_mesh(): nx, ny, nz = 3, 2, 2 F = simple.cuboid().replic2(nx, ny).replic(nz, 1., 2) F += F.trl([nx, ny, 0]) F += F.trl([2*nx, 2*ny, nz]) return F.toMesh()