예제 #1
0
    def AddSquare(self, s, va, vb, vc, vd, revert=0):
        # currently implemented lamely: two triangles:  ABC, ACD.
        # FIXME: this should be 4 triangles with an interpolated midpoint.

        # create ABC triangle, counterclockwise
        eab = gts.Edge(va, vb)  # the order of the Vertexes here is
        ebc = gts.Edge(vb, vc)  # important, and determine the direction
        eca = gts.Edge(vc, va)  # of the normal vector.
        f1 = gts.Face(eab, ebc, eca)  # ccw

        # create ACD triangle, counterclockwise
        eac = gts.Edge(va, vc)
        ecd = gts.Edge(vc, vd)
        eda = gts.Edge(vd, va)
        f2 = gts.Face(eac, ecd, eda)  # ccw
        # create two triangles.  Assume left-hand rule for computing normal
        # from the ordering of the edges.  Assume the normal points out of
        # the surface of a solid object.  So we traverse the edges clockwise,
        # looking at the face from the outside.
        if revert:
            # turn around, bright eyes.
            f1.revert()
            f2.revert()
        # add faces to object
        for face in [f1, f2]:
            if not face.is_compatible(s):
                print "surprise!"  # this should never happen if order of edge
                face.revert()  # construction above is correct.
            s.add(face)  # will only collapse edges if normals are correct
예제 #2
0
파일: pack.py 프로젝트: Zhijie-YU/yade-copy
 def doCap(vtx, edg, start):
     ret = []
     eFan = [edg[0]
             ] + [gts.Edge(vtx[i], vtx[0]) for i in range(2, len(vtx))]
     for i in range(1, len(edg)):
         ret += [
             gts.Face(eFan[i - 1], eFan[i], edg[i]) if start else gts.Face(
                 eFan[i - 1], edg[i], eFan[i])
         ]
     return ret
예제 #3
0
def sweptPolylines2gtsSurface(pts,threshold=0,capStart=False,capEnd=False):
	"""Create swept suface (as GTS triangulation) given same-length sequences of points (as 3-tuples).

If threshold is given (>0), then

* degenerate faces (with edges shorter than threshold) will not be created
* gts.Surface().cleanup(threshold) will be called before returning, which merges vertices mutually closer than threshold. In case your pts are closed (last point concident with the first one) this will the surface strip of triangles. If you additionally have capStart==True and capEnd==True, the surface will be closed.

.. note:: capStart and capEnd make the most naive polygon triangulation (diagonals) and will perhaps fail for non-convex sections.

.. warning:: the algorithm connects points sequentially; if two polylines are mutually rotated or have inverse sense, the algorithm will not detect it and connect them regardless in their given order.
	"""
	import gts # will raise an exception in gts-less builds
	if not len(set([len(pts1) for pts1 in pts]))==1: raise RuntimeError("Polylines must be all of the same length!")
	vtxs=[[gts.Vertex(x,y,z) for x,y,z in pts1] for pts1 in pts]
	sectEdges=[[gts.Edge(vtx[i],vtx[i+1]) for i in range(0,len(vtx)-1)] for vtx in vtxs]
	interSectEdges=[[] for i in range(0,len(vtxs)-1)]
	for i in range(0,len(vtxs)-1):
		for j in range(0,len(vtxs[i])):
			interSectEdges[i].append(gts.Edge(vtxs[i][j],vtxs[i+1][j]))
			if j<len(vtxs[i])-1: interSectEdges[i].append(gts.Edge(vtxs[i][j],vtxs[i+1][j+1]))
	if threshold>0: # replace edges of zero length with None; their faces will be skipped
		def fixEdges(edges):
			for i,e in enumerate(edges):
				if (Vector3(e.v1.x,e.v1.y,e.v1.z)-Vector3(e.v2.x,e.v2.y,e.v2.z)).norm()<threshold: edges[i]=None
		for ee in sectEdges: fixEdges(ee)
		for ee in interSectEdges: fixEdges(ee)
	surf=gts.Surface()
	for i in range(0,len(vtxs)-1):
		for j in range(0,len(vtxs[i])-1):
			ee1=interSectEdges[i][2*j+1],sectEdges[i+1][j],interSectEdges[i][2*j]
			ee2=sectEdges[i][j],interSectEdges[i][2*j+2],interSectEdges[i][2*j+1]
			if None not in ee1: surf.add(gts.Face(interSectEdges[i][2*j+1],sectEdges[i+1][j],interSectEdges[i][2*j]))
			if None not in ee2: surf.add(gts.Face(sectEdges[i][j],interSectEdges[i][2*j+2],interSectEdges[i][2*j+1]))
	def doCap(vtx,edg,start):
		ret=[]
		eFan=[edg[0]]+[gts.Edge(vtx[i],vtx[0]) for i in range(2,len(vtx))]
		for i in range(1,len(edg)):
			ret+=[gts.Face(eFan[i-1],eFan[i],edg[i]) if start else gts.Face(eFan[i-1],edg[i],eFan[i])]
		return ret
	caps=[]
	if capStart: caps+=doCap(vtxs[0],sectEdges[0],start=True)
	if capEnd: caps+=doCap(vtxs[-1],sectEdges[-1],start=False)
	for cap in caps: surf.add(cap)
	if threshold>0: surf.cleanup(threshold)
	return surf
예제 #4
0
def unitSquare():
    """Return square composed of 2 facets in the xy plane, centered at zero with unit extents."""
    import gts
    vv = [
        gts.Vertex(1, 1, 0),
        gts.Vertex(-1, 1, 0),
        gts.Vertex(-1, -1, 0),
        gts.Vertex(1, -1, 0)
    ]
    ee = [
        gts.Edge(vv[0], vv[1]),
        gts.Edge(vv[1], vv[2]),
        gts.Edge(vv[2], vv[3]),
        gts.Edge(vv[3], vv[0]),
        gts.Edge(vv[0], vv[2])
    ]
    surf = gts.Surface()
    surf.add(gts.Face(ee[0], ee[1], ee[4]))
    surf.add(gts.Face(ee[2], ee[3], ee[4]))
    return surf
예제 #5
0
def test_tetrahedron():
    """
    A tetrahedron is assembled from these primitives as follows.  
    First, create Vertices for each of the tetrahedron's points:
    """
    v1 = gts.Vertex(1, 1, 1)
    v2 = gts.Vertex(-1, -1, 1)
    v3 = gts.Vertex(-1, 1, -1)
    v4 = gts.Vertex(1, -1, -1)
    """
    Next, connect the four vertices to create six unique Edges:
    """
    e1 = gts.Edge(v1, v2)
    e2 = gts.Edge(v2, v3)
    e3 = gts.Edge(v3, v1)
    e4 = gts.Edge(v1, v4)
    e5 = gts.Edge(v4, v2)
    e6 = gts.Edge(v4, v3)
    """
    The four triangular faces are composed using three edges each:
    """
    f1 = gts.Face(e1, e2, e3)
    f2 = gts.Face(e1, e4, e5)
    f3 = gts.Face(e2, e5, e6)
    f4 = gts.Face(e3, e4, e6)
    """
    Finally, the surface is assembled from the faces.
    Some care must be taken in the orientation of the faces.  
    In the above example, the surface normals are pointing inward, 
    and so the surface technically defines a void, rather than a solid.  
    To create a tetrahedron with surface normals pointing outward, 
    use the following instead:
    """
    s = gts.Surface()
    for face in [f1, f2, f3, f4]:
        if not face.is_compatible(s):
            face.revert()
        s.add(face)

    print s.volume()
    print s.center_of_mass()
예제 #6
0
    def convert(self):
        """
Converts the data from the current/last mesh node. Each triangle is made up of
1 or more triangles.
		"""
        tri = []
        self.surface = gts.Surface()
        for index in self.indices:
            tri.append(index)

            # for every group of 3 indicies
            if 3 == len(tri):
                e1 = gts.Edge(self.vertices[tri[0]], self.vertices[tri[1]])
                e2 = gts.Edge(self.vertices[tri[1]], self.vertices[tri[2]])
                e3 = gts.Edge(self.vertices[tri[2]], self.vertices[tri[0]])
                self.surface.add(gts.Face(e1, e2, e3))
                tri = []
예제 #7
0
edge = []
for i in list(range(discret)):
    if i == discret - 1:
        edge.append([
            gts.Edge(pcenter, pt[i]),
            gts.Edge(pt[i], pt[0]),
            gts.Edge(pt[0], pcenter)
        ])
    else:
        edge.append([
            gts.Edge(pcenter, pt[i]),
            gts.Edge(pt[i], pt[i + 1]),
            gts.Edge(pt[i + 1], pcenter)
        ])

# creation des faces des triangles
face = []
for i in list(range(discret)):
    face.append(gts.Face(edge[i][0], edge[i][1], edge[i][2]))

# creation de la surface et importation dans la simulation
s = gts.Surface()
for i in list(range(discret)):
    s.add(face[i])

#print s.area()
#print math.pi*radius**2.

facet = gtsSurface2Facets(s, wire=False, material=wallMat)
O.bodies.append(facet)
예제 #8
0
                          memoizeDb='/tmp/gts-triax-packings.sqlite',
                          returnSpherePack=True)
sp.toSimulation(color=(0.9, 0.8, 0.6), wire=False, material=mat)
print('Sphere sample generated !')

# --- The joint surface : half of the height
import gts
v1 = gts.Vertex(0, 0, Lz / 2.0)
v2 = gts.Vertex(Lx, 0, Lz / 2.0)
v3 = gts.Vertex(Lx, Ly, Lz / 2.0)
v4 = gts.Vertex(0, Ly, Lz / 2.0)

e1 = gts.Edge(v1, v2)
e2 = gts.Edge(v2, v4)
e3 = gts.Edge(v4, v1)
f1 = gts.Face(e1, e2, e3)

e4 = gts.Edge(v4, v3)
e5 = gts.Edge(v3, v2)
f2 = gts.Face(e2, e4, e5)

s1 = gts.Surface()
s1.add(f1)
s1.add(f2)

facet = gtsSurface2Facets(s1, wire=False, material=mat)
O.bodies.append(facet)

# --- Identification of spheres onJoint, and so on:
execfile('identifBis.py')
예제 #9
0
    #
    #    t = tuple((i[0],i[1],i[2]) for i in indices)
    #
    #    mlab.triangular_mesh(x,y,z,t,color=(0.8,0.8,0.8))
    #    mlab.triangular_mesh(x,y,z,t,color=(0,0,1),representation='fancymesh',
    #                         scale_factor=.00000001)
    #    mlab.show()
    vertices_gts = [gts.Vertex(v[0], v[1], v[2]) for v in vertices]
    edges_gts = []
    faces_gts = []
    for tri in indices:
        #print tri,
        edges_gts.append(gts.Edge(vertices_gts[tri[0]], vertices_gts[tri[1]]))
        edges_gts.append(gts.Edge(vertices_gts[tri[1]], vertices_gts[tri[2]]))
        edges_gts.append(gts.Edge(vertices_gts[tri[2]], vertices_gts[tri[0]]))
        faces_gts.append(gts.Face(edges_gts[-3], edges_gts[-2], edges_gts[-1]))
#    for i in xrange(0,len(edges_gts),3):
#        faces_gts.append(gts.Face(edges_gts[i],edges_gts[i+1],edges_gts[i+2]))

    s = gts.Surface()
    for face in faces_gts:
        #if not face.is_compatible(s):
        #    face.revert()
        #if face.is_compatible(s):
        #    s.add(face)
        s.add(face)

    #print s.volume()
    #print s.center_of_mass()
    plot_surface(s)
    mlab.show()